collection
-
在内置数据类型的基础上,增加了几个额外的数据类型
-
namedtuple
-
生成可以还是用名字来访问元素内容的tuple
-
写元组的时候,例如经纬度
-
from collections import namedtuple Point = namedtuple('Point', ['x', 'y']) #x,y元组参数 p = Point(1, 2)#Point:命名元组的元组名字 print(p)
-
-
deque
- 双端队列,可以快速的从另外一侧追加和推出对象
- pass
-
counter
-
计数器,主要是用来计数
-
计算每个元素出现的次数
-
from collections import Counter # s = "1112233344aaa" # s = [1,1,2,2,3,3] # s = (1,2,3,3,4,5,6,7,78) # print(dict(Counter(s))) # *** # 统计元素出现的次数
-
-
orderedict
- 有序字典
- pass
-
defaultdict
- 带有默认值的字典
- pass