在可迭代对象中查找最常见的元素

collections 可以对可迭代对象内容进行统计

>>> import collections        # 引入collections库
>>> c = collections.Counter('helloworld')    # 统计字母个数

>>> c
Counter({'l': 3, 'o': 2, 'e': 1, 'd': 1, 'h': 1, 'r': 1, 'w': 1})

>>> c.most_common(3)   # 输出最多的几个
[('l', 3), ('o', 2), ('e', 1)]