【python】词频统计

#KochDrawV2.py
import jieba

txt = open("C:\\Users\\94079\\Desktop\\test.txt","r",encoding="utf-8").read()
words = jieba.lcut(txt)
counts = {}
for word in words:
    if len(word) == 1:
        continue

counts[word] = counts.get(word,0)+1
items = list(counts.items())
items.sort(key = lambda x:x[1],reverse = True)
print(items)
for i in range(200):
    word,count = items[i]
    print("NO.{}: W:{} T:{} ".format(i+1,word,count))
发布了38 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_41514794/article/details/89446086