统计中文文章词频

f=open("C:/Users/ZD/PycharmProjects/test/test.txt",'r',encoding='utf8')
str=f.read()
f.close()
import jieba

wordList=jieba.cut(str)
wordList=list(jieba.cut(str))

wordDic={}
for i in set(wordList):
    wordDic[i]=wordList.count(i)

sort_word=sorted(wordDic.items(),key=lambda d:d[1],reverse=True)
for i in range(20):
    print(sort_word[i])

  

 

posted on 2018-03-28 15:20  阿丹丹酱  阅读(213)  评论(0编辑  收藏  举报

导航