deque 线程安全的双向队列
In [104]: q = collections.deque()
In [105]: q.append(1)
In [106]: q.append(2)
In [107]: q
Out[107]: deque([1, 2])
In [108]: q.appendleft(4)
In [109]: q
Out[109]: deque([4, 1, 2])
clear()
清除队列
count(x)
计算队列中等于 x 的元素个数
In [116]: q
Out[116]: deque([2, 4, 1, 2])
In [117]: q.count(2)
Out[117]: 2
In [118]: q.count(1)
Out[118]: 1
-
extend(iterable)
在队列的右边扩展可迭代的队列
In [119]: q.extend([6,7,8])
In [120]: q
Out[120]: deque([2, 4, 1, 2, 6, 7, 8])
In [120]: q
Out[120]: deque([2, 4, 1, 2, 6, 7, 8])
In [122]: q.remove(2)
In [123]: q
Out[123]: deque([4, 1, 2, 6, 7, 8])
In [127]: q
Out[127]: deque([1, 4, 8, 7, 6, 2])
In [128]: q.rotate(3)
In [131]: q
Out[131]: deque([7, 6, 2, 1, 4, 8])