首页 > 其他 > 详细

西游记 词频统计

时间:2020-04-05 18:29:37      阅读:89      评论:0      收藏:0      [点我收藏+]
 1 import jieba
 2 txt=open("D://python_common_exercise//west_journey.txt",r,encoding="utf-8").read()
 3 words=jieba.lcut(txt)   #jieba库函数
 4 count={}    #创建字典
 5 for word in words:
 6     if len(word)==1:
 7         continue
 8     else:
 9         count[word]=count.get(word,0)+1
10 items=list(count.items())   #转换成列表
11 items.sort(key=lambda x:x[-1],reverse=True)
12 for i in range(15):
13     word,count=items[i]
14     print("{0:<10}{1:>5}".format(word,count))

技术分享图片

 

西游记 词频统计

原文:https://www.cnblogs.com/hrunjie/p/12638185.html

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