综合练习 词频统计
f = open('C:\Users\Administrator\Desktop\s.txt', 'r', encoding='utf-8')
a = f.read()
d = {}
h = '''.'!?:,'''
danci = ['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 danci:
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)