统计词频

 1 #统计词频,可以根据需要统计句子或文本
 2 txt = 'this is a student there is a bag'
 3 words = txt.split()
 4 dict = {}
 5 for w in words:
 6     if w not in dict:
 7         dict[w] = 1
 8     else:
 9         dict[w] = dict[w] + 1
10 print dict
原文地址:https://www.cnblogs.com/cdsj/p/3538180.html