import collections
import queue
collections.deque
q = queue.Queue()
lq = queue.LifoQueue()
l = []
d = collections.deque()
for i in range(3):
q.put(i)
lq.put(i)
l.append(i)
d.append(i)
for _ in range(3):
print('FIFO queue = {}'.format(q.get()))
print('LIFO queue = {}'.format(lq.get()))
print('list = {}'.format(l.pop())) #pop(0)でFIFO
print('deque = {}'.format(d.pop())) #d.popleft()でFIFO
print()
実行結果:
FIFO queue = 0
LIFO queue = 2
list = 2
deque = 2
FIFO queue = 1
LIFO queue = 1
list = 1
deque = 1
FIFO queue = 2
LIFO queue = 0
list = 0
deque = 0
import collections
import queue
collections.deque
d = collections.deque()
for i in range(3):
d.append(i)
print(d)
d.extendleft('x')
d.extend('y')
print(d)
d.rotate()
print(d)
d.clear()
print(d)
実行結果:
deque([0, 1, 2])
deque(['x', 0, 1, 2, 'y'])
deque(['y', 'x', 0, 1, 2])
deque([])