出一个序列中出现次数最多的元素
方法一:
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)
print(word_counts) #返回字典
top_three=word_counts.most_common(3)
print(top_three)
方法2:利用字典手动实现