collections模块 2020年8月16

from collections import namedtuple

Point = namedcuple(‘point’, [’x’,’y’])

p = Point(1,2)

print(p.x,p.y)     print(p)  # point(x=1,y=2)

 

from collections import deque      (双端队列)

q = deque([1,2])

q.append()    #从后面放数据

q.appendleft()  #从前面放数据

q.pop()     #从后面取数据

q.popleft()   #从前面取数据

 

from collections import OrderedDict    (有序字典)

od = OrderdDirt([(‘a’,1),(‘b’,2),(‘c’,3)])

 

from collections import defaultdict

d = defaultdict()    #参数必须是callable的

原文地址:https://www.cnblogs.com/liu1983/p/13513019.html