标签:else test 分词 key .so lam count port 合并
.中文分词
import jieba txt = open(‘test.txt‘,‘r‘,encoding=‘utf-8‘).read() for i in ‘,。“” ;:?、\n‘: txt=txt.replace(i,‘‘) words = list(jieba.cut(txt)) dic={} keys=set(words) for j in keys: if len(j)==1: continue else: dic[j]=words.count(j)+1 wc=list(dic.items()) wc.sort(key= lambda x:x[1],reverse=True) for i in range(10): print(wc[i])
标签:else test 分词 key .so lam count port 合并
原文地址:http://www.cnblogs.com/lzp963/p/7610561.html