其他分享
首页 > 其他分享> > 使用Counter类找出序列中出现次数最多的元素

使用Counter类找出序列中出现次数最多的元素

作者:互联网

"""
找出序列中出现次数最多的元素
"""
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'
]
counter = Counter(words)
print(counter.most_common(3))

标签:找出,look,into,Counter,eyes,dict,序列,my
来源: https://blog.csdn.net/Cdlg_Fans/article/details/121915430