用python统计一个pdf文件前20个高频词汇

def getText():
    txt = open("deram.txt", "r").read()
    txt = txt.lower()
    for ch in '!"#$%&()*+,-./:;<=>?@[\\]^_‘{|}~':
        txt = txt.replace(ch, " ")   
    return txt
dreamTxt = getText()
words  = dreamTxt.split()
counts = {}
for word in words:   
    counts[word] = counts.get(word,0) + 1
items = list(counts.items())
items.sort(key=lambda x:x[1], reverse=True) 
for i in range(10):
    word, count = items[i]
    print ("{0:<10}{1:>5}".format(word, count))

 

 

各位大佬,麻烦看看在这个基础上咋改啊

提前谢谢啦

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^