把内容替换一下就行了
hamletText = "asd fasd asd a asd as as f as da asd "
words = hamletText.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(len(items)):
word,count = items[i]
print("{0:<10}{1:>5}".format(word,count))
https://blog.csdn.net/codejas/article/details/80356544?utm_source=app&app_version=4.9.3&code=app_1562916241&uLinkId=usr1mkqgl919blen
推荐这篇文章,很详细,希望可以帮助你