快速的统计一个字典里面每个元素出现的次数
import collections
most_common = collections.Counter(['a', 'a', 'b' ]).most_common()
print(most_common)
[('a', 2), ('b', 1)]
注意上面的参数必须是list类型的,不能是二维的,或者其他维度的
比如下面的代码因为维度不对,就会报错
a = [
[1, 2, 3],
[4, 5, 6]
]
most_common = collections.Counter(a).most_common()
print(most_common)
TypeError: unhashable type: 'list'