中文统计

import jieba
txt=open('a.txt','r',encoding='utf-8').read()
words=list(jieba.cut(txt))
print(words)




d={}
for w in words:
    if len(w)==1:
        continue
    else:
        d[w]=d.get(w,0)+1#去除单个字典
print(words)
    
        

ls=list(d.items())#元组的列表
ls.sort(key=lambda x:x[1],reverse=True)#列表排序

for i in range(20):#输出TOP20元组
    print(ls[i])

  

posted on 2017-09-29 09:52  张木清  阅读(93)  评论(0编辑  收藏  举报

导航