Python实例:查找序列中出现次数最多的元素

# coding:utf-8

'''
查找序列中出现次数最多的元素
'''

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'
]
from collections import Counter
word_counts = Counter(words)
# 出现频率最高的3 个单词
top_three = word_counts.most_common(3)
print(top_three)

猜你喜欢

转载自my.oschina.net/wujux/blog/1786267
今日推荐