利用Python的collections包下Counter的类统计每个数据出现的个数
from collections import Counter a = [1, 2, 3, 1, 1, 2] result = Counter(a) print result
输出:
{1: 3, 2: 2, 3: 1}
时刻记着自己要成为什么样的人!
from collections import Counter a = [1, 2, 3, 1, 1, 2] result = Counter(a) print result
输出:
{1: 3, 2: 2, 3: 1}