中文词频统计

#coding=utf--8
import jieba
exclude={',','','','u3000','
','"',"",'','?'}
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])
原文地址:https://www.cnblogs.com/swxvico/p/8660858.html