python 关于词频统计的程序 打印出的高频率单词把他们用便利贴记下来帮助自己学英语(统计小说,或者爬虫采集英文小说)

import re
# 月亮与六便士共7313词
# 傲慢与偏见加上面这本书共这么多词10781
s="I'm a father."
with open("EnglishNovels/pride.txt", "r", encoding='utf8') as f:
   pattern=re.compile("[A-Za-z'’]+")
   words=pattern.findall(f.read())
   a=dict()
   for i in words:
       if i not in a:
           a[i]=1
       else:
           a[i]+=1

print(len(a)) print(sorted(a.items(),key = lambda x:x[1],reverse = True))

  

 

posted @ 2020-05-02 17:25  我爱黑科技77  阅读(207)  评论(0编辑  收藏  举报