用户:
少幽科技查看:4 回复:2 评论:4 创建时间:2020-03-31T20:55:27
import string
from collections import Counter
show = 3
outtab = ' '*len(string.punctuation)
intab = string.punctuation
text = '''text here'''
text = text.lower()
text = text.translate(str.maketrans(intab,outtab))
words = text.split()
count = Counter(words)
top = count.most_common(show)
print('\n'.join([f'word:"{word}", times:{time}' for word,time in top]))