【发布时间】:2019-02-28 05:29:20
【问题描述】:
我很难找到解决问题的方法,也许有人可以提供帮助。我有一首诗,我能够显示最常见的单词,尽管我希望所有长度小于 5 个字符的字符串都不会显示在我的前 20 个最常见的列表中。
import collections
import re
words = re.findall(r'\w+', open('some_poem.txt').read().lower())
most_common = collections.Counter(words).most_common(20)
print(most_common)
是否有一种简洁明了的方法来添加此类功能?不显示 5 个字符或更少的字符串?提前致谢
【问题讨论】:
标签: python word-count