利用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}

posted @ 2018-12-25 13:53  今夜无风  阅读(1046)  评论(0编辑  收藏  举报