Fork me on GitHub

统计一篇英文文章内每个单词出现频率,并返回出现频率最高的前10个单词及其出现次数

from collections import Counter
import re

with open('a.txt', 'r', encoding='utf-8') as f:
    txt = f.read()
c = Counter(re.split('\W+',txt))  #取出每个单词出现的个数
print(c)
ret = c.most_common(10)   #取出频率最高的前10个
print(ret)

  

posted on 2018-03-03 13:11  vmaze  阅读(795)  评论(0编辑  收藏  举报

导航