fo = open("1.txt", "r", encoding='utf-8')
read = fo.read()
fo.close()

read = read.strip().lower()
for i in '''.,?;:''':
read = read.replace(i, ' ')

readList = read.split()

readSet = set(readList)
bug = {'i', 'my', 'but', 'and', 'you', 'the', 'if', 'on', 'are'}
readSet = readSet - bug

dic = {}
for word in readSet:
dic[word] = readList.count(word)

li = list(dic.items())
li.sort(key=lambda x: x[1], reverse=True)

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


posted on 2018-10-15 11:45  詫秺  阅读(107)  评论(0编辑  收藏  举报