码迷,mamicode.com
首页 > 其他好文 > 详细

中文词频统计

时间:2018-03-28 00:00:38      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:ict   style   set   dict   \n   reverse   imp   list   词频统计   

#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])

 

中文词频统计

标签:ict   style   set   dict   \n   reverse   imp   list   词频统计   

原文地址:https://www.cnblogs.com/swxvico/p/8660858.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!