deque
say it: “DEK” /dɛk/
A list built for quickly adding and removing at both ends.
What is a deque?
A deque (say "deck") is a list built for adding and removing at both ends quickly, perfect for queues and "last N items" lists.
from collections import deque
recent = deque(maxlen=3) # keeps only the last 3
for page in ["home", "shop", "cart", "checkout"]:
recent.append(page)
print(list(recent)) # ['shop', 'cart', 'checkout']
Level: Freelancer · More Python terms at this level
Updated