问题
《Python Cookbook》中有这么一个问题,给定一个序列,找出该序列出现次数最多的元素。
例如:html
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'
]
统计出words中出现次数最多的元素?python
初步探讨
一、collections模块的Counter类
首先想到的是collections模块的Counter类,centos
from collections import Counter
words = [
'look', 'into', 'my', 'eyes', 'look', 'into', 'my', 'e