https://docs.python.org/zh-cn/3/library/collections.html
# # Author: Sooele # import collections # from collections import deque # d = deque('ghi') # # for elem in d: # iterate over the deque's elements # print(elem.upper()) # # Point = collections.namedtuple('Point', ['x', 'y']) # p = Point(11, y=22) # p[0] + p[1] # print(p) # # dict = p._asdict() # # print(type(dict)) # # s = p._fields # print(type(s)) from collections import Counter mystring = ['a','b','c','d','d','d','d','c','c','e'] # 取得频率最高的前三个值 cnt = Counter(mystring) cnt.most_common(3) cnt['b'] print(cnt) # 命名元组 from collections import namedtuple Point = namedtuple('Ponit', ['x','y']) p = Point(10, y=20) p.x + p.y p[0] + p[1] x, y = p # 双向队列 from collections import deque d = deque('uvw') d.append('xyz') d.appendleft('rst')