代码改变世界

中文词频统计

2017-09-29 11:28  082何晓琳  阅读(162)  评论(0编辑  收藏  举报
import jieba
t=open('0082.txt','r',encoding='utf-8').read()
word=list(jieba.cut(t))
exp={'',''}
keys=set(word)-exp
dic={}
for w in keys:
    if len(w)>1:
        dic[w]=word.count(w)


c=list(dic.items())
c.sort(key=lambda x:x[1],reverse=True)
for i in range(15):print(c[i])

此语段是在郭敬明的小说《夏至未至》中截取出来了,由结果可知,此小说是讲述男女主角青春时代的故事。