文件方式实现完整的英文词频统计实例

4.排除语法型词汇

exp={'','to','have','a'}
keys=set(words)-exp#出现过单词的集合,字典的key.

5.排序

for i in keys:
    d[i]=words.count(i)
#print(d)
wc=list(d.items())
wc.sort(key=lambda x:x[1],reverse=True)#排序
print(wc)

6.输出TOP(20)

for i in range(20):
    print(wc[i])

 

posted @ 2017-09-26 21:22  018林彬  阅读(173)  评论(0编辑  收藏  举报