jieba

 1 #jieba文本分析
 2 import jieba
 3 txt = open("C:/Users/86136/Documents/python文件测试/test.txt","rt",encoding="utf-8")
 4 words=jieba.lcut(txt.read())
 5 counts={}
 6 for word in words:
 7     if len(word)==1:
 8         continue
 9     else:
10         counts[word]=counts.get(word,0)+1
11 items=list(counts.items())
12 items.sort(key=lambda x:x[1],reverse=True)
13 for i in range(20):
14     word,count = items[i]
15     print("{0:<10}{1:>5}".format(word,count))
16 txt.close()

jieba_第1张图片

 

你可能感兴趣的:(jieba)