标签:encoding == lambda com jieba 统计 png imp continue
import jieba fo=open(‘xiyouji.txt‘,‘r‘,encoding=‘utf-8‘) str=fo.read() fo.close() words=list(jieba.cut(str)) dt={} for i in words: if len(i)==1: continue else: dt[i]=dt.get(i,0)+1 item=list(dt.items()) item.sort(key=lambda x:x[1],reverse=True) for i in range(20): print(item[i])
运行结果:
标签:encoding == lambda com jieba 统计 png imp continue
原文地址:http://www.cnblogs.com/Naiky/p/7610640.html