标签:统计 reverse src 词频统计 encoding lis alt .com ima
中文分词
import jieba fo = open(‘傲慢与偏见前十章.txt‘,‘r‘,encoding=‘utf-8‘).read() words = list(jieba.cut(fo,cut_all=True)) for i in ‘‘‘,。:‘’“”?!\n \u3000\u3000‘‘‘: fo = fo.replace(i,‘ ‘) words = fo.split(‘ ‘) exp={‘‘,‘噢‘,‘唔‘,‘她说‘,‘啊‘} dic={} keys=set(words)-exp for w in keys: 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])
标签:统计 reverse src 词频统计 encoding lis alt .com ima
原文地址:http://www.cnblogs.com/yangjlee/p/7610451.html