中文词频统计

#coding=utf--8
import jieba
exclude={',','','','\u3000','\n','"',"",'','?'}
txt=open('doupo.txt','r').read()
wordList=list(jieba.cut(txt))
wordSet=set(wordList)-exclude
wordDict={}
for w in wordSet:
    wordDict[w]=wordList.count(w)
dictList=list(wordDict.items())
dictList.sort(key=lambda x:x[1],reverse=True)
for i in range(20):
    print (dictList[i])

 

posted @ 2018-03-27 22:53  160苏伟祥  阅读(87)  评论(0编辑  收藏  举报