from collections import Counter
words = [
'look', 'into', 'my', 'eyes', 'look', 'into', 'my', 'eyes',
'the', 'eyes', 'the', 'eyes', 'the', 'eyes', 'not', 'around', 'the',
'eyes', "don't", 'look', 'around', 'the', 'eyes', 'look', 'into',
'my', 'eyes', "you're", 'under'
]
word_counts = Counter(words)
# 找出出现次数最多的3个元素
print(word_counts.most_common(3))
# 打印结果为:
[('eyes', 8), ('the', 5), ('look', 4)]
Counter找出频率最高
最新推荐文章于 2023-03-07 15:24:27 发布