import jieba
txt=open("C:\\Users\\11765\Desktop\\新建 文本文档.txt", "r", encoding='utf-8').read()
words=jieba.lcut(txt)
counts={}
for word in words:
if len(word) ==1:
continue
else:
counts[word]=counts.get(word,0)+1
it=list(counts.items())
it.sort(key=lambda x:x[1],reverse=True)
for i in range(20):
word, count =it[i]
print("{0:<10}{1:>5}".format(word, count))
jieba库红楼梦分词
最新推荐文章于 2024-08-16 20:07:09 发布