Python collections模块

返回列表或字符串等中字符出现次数的字典:

>>> import collections
>>> a = 'ddsdsdsdsf'
>>> collections.Counter(a)
Counter({'d': 5, 's': 4, 'f': 1})
>>> a = [1,1,2,2,0]
>>> collections.Counter(a)
Counter({1: 2, 2: 2, 0: 1})
posted @ 2018-10-13 19:33  epiphanyy  阅读(6)  评论(0)    收藏  举报  来源