Python3—— collections模块
collections的常用类型有: 计数器(Counter) 双向队列(deque) 默认字典(defaultdict) 有序字典(OrderedDict) 可命名元组(namedtuple) 使用以上类型时需要导入模块 from collections import * collections是Python内建的一个集合模块,提供了许多有用的集合类 1. Counter Counter作为字典(dict)的一个子类用来进行hashtable计数,将元素进行数量统计、计数后返回一个字典,键值为元素:值为元素个数 [python] view plain copy s='abcbcaccbbad' l=['a','b','c','c','a','b','b'] d={'2':3,'3':2,'17':2} #Counter获取各元素的个数,返回字典 print(Counter(s))#Counter({'c':4,'b':4,'a':3}) print(Counter(l))#Counter({'b':3,'a':2,'c':2}) print(Counter(d))#Counter({...