标准库之collections

# 命名元组
# from collections import namedtuple
#
# p = namedtuple('point', ['x', 'y'])
# p1 = p(4,3)
# p2 = p(3,4)
# print(p1.x)
# print(p2.y)
# print(p(4,3))

# 双栈队列
# from collections import deque
# l = [1,2]
# dq = deque(l)
# dq.append(3)
# dq.appendleft(0)
# dq.insert(4,5)
# print(dq.pop())
# print(dq.popleft())
# print(dq)

# # 有序的字典
# from collections import OrderedDict
#
# od = OrderedDict([('a', 1), ('b', 2), ('c', 3)])
# print(od)
# print(od['b'])
# for i in od.items():
#     print(i)

# 默认字典
# from collections import defaultdict
# d = defaultdict(lambda : 5)
# print(d['a'])

猜你喜欢

转载自www.cnblogs.com/hhsh/p/9581869.html