标签:[1] key http class utf-8 小说 list pre 词频统计
中文分词
import jieba n=open(‘0.txt‘,‘r‘,encoding=‘utf-8‘).read() words=list(jieba.cut(n)) exp={‘,‘,‘.‘,‘\n‘} keys=set(words)-exp dic={} for w in keys: if len(w)>1: dic[w]=words.count(w) wc=list(dic.items()) wc.sort(key=lambda x:x[1],reverse=True) for i in range(20): print(wc[i])
标签:[1] key http class utf-8 小说 list pre 词频统计
原文地址:http://www.cnblogs.com/ffr0068/p/7610497.html