首页 > 其他 > 详细

jieba

时间:2020-04-09 20:18:49      阅读:56      评论:0      收藏:0      [点我收藏+]
 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

原文:https://www.cnblogs.com/1234f/p/12669214.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!