首页 > 其他 > 详细

jieba库

时间:2020-06-22 21:20:23      阅读:75      评论:0      收藏:0      [点我收藏+]

import jieba
txt = open("文章.txt","r",encoding=‘gbk‘,errors=‘replace‘).read()
words  = jieba.lcut(txt)
counts = {}
for word in words:
    if len(word) == 1:
        continue
    else:
        counts[word] = counts.get(word,0) + 1
       
items = list(counts.items())
items.sort(key=lambda x:x[1], reverse=True)
for i in range(15):
    word, count = items[i]
    print ("{0:<10}{1:>5}".format(word, count))

jieba库

原文:https://www.cnblogs.com/study007/p/13178971.html

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