综合练习:词频统计

f = open('C:\\Users\\Administrator\\Desktop\\14.txt', 'r', encoding='utf-8')
a = f.read()
d = {}
h = '''.'!?:,'''
D = ['the', 'and', 'a']
for j in h:
    b = set(a.replace("\'", "").lower().split())
for v in b:
    d[v] = a.count(v)
for ec in D:
    d.pop(ec)
e = list(d.items())
e.sort(key=lambda x: x[1], reverse=True)
for k,v in enumerate(e):
    if k < 20:
        print(v)

posted @ 2018-03-26 11:39  090伍明航  阅读(130)  评论(0编辑  收藏  举报