司徒春燕

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
import jieba

f = open('article.txt','r',encoding='utf-8')
text = f.read()
f.close()
stri = '''一!“”,。?;’"',.、:\n'''
for s in stri:
    text = text.replace(s,' ')
wordlist = list(jieba.cut(text))
exclude = {'','你们','','','','','','','','他们','','','','','','','',
           '','','可是','自己','','','什么','','一个',' ','','','','一点','','',
           '没有','','','','','','','','','不是','','但是','已经','那么','','因为',}
set = set(wordlist) - exclude
dict = {}
for key in set:
    dict[key]=wordlist.count(key)
dictlist = list(dict.items())
dictlist.sort(key=lambda x: x[1], reverse=True)
f1 = open('articleCount.txt', 'a',encoding='utf-8')
for i in  range(20):
    f1.write(str(dictlist[i])+'\n')
    print(dictlist[i])
f1.close()

结果截图:

 

posted on 2018-03-28 17:32  187司徒春燕  阅读(110)  评论(0编辑  收藏  举报