统计西游记词频
作者:互联网
利用jieba库统计西游记重出现最多次的20个词
import jieba f = open('4447.txt', mode='r',encoding='GB18030') txt = f.read() txt = jieba.lcut(txt) buyao = ['。',',',':','“','”','?','、','《','》','!','!','\n'] count = {} for ch in txt: if ch not in buyao: count[ch] = count.get(ch, 0) + 1 items = list(count.items()) items.sort(key=lambda x: x[1], reverse=True) for i in range(20): rw, gs=items[i] print("{0:5} {1:5}".format(rw, gs))
通过运行结果我们可以看出,西游记的描述多是采用第一人称的方式
标签:count,jieba,ch,items,词频,txt,西游记,统计 来源: https://www.cnblogs.com/quanshi/p/15550700.html