码迷,mamicode.com
首页 > 其他好文 > 详细

jiaba库的使用《活着》字频分析

时间:2020-04-07 22:51:50      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:form   img   nts   list   mic   coding   tin   ima   图片   

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

技术图片

jiaba库的使用《活着》字频分析

标签:form   img   nts   list   mic   coding   tin   ima   图片   

原文地址:https://www.cnblogs.com/wangyingjie123/p/12656289.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!