中文词频统计及词云制作
代码部分:
import jieba txt = open("最后一颗子弹留给我.txt","r",encoding='utf-8').read() a = jieba.cut(txt) counts = {} for b in a: if len(b) == 1: continue else: counts[b] = counts.get(b,0) + 1 items = list(counts.items()) items.sort(key=lambda x:x[1],reverse=True) for i in range(20): b,count = items[i] print("{0:<6}{1:>3}".format(b,count))
结果:

最重要的词是“大队”,也符合小说剧情

浙公网安备 33010602011771号