Queues, Deques & Up-Next
In short: a queue serves whatever has waited longest. Enqueue
adds at the back, dequeue removes from the front — FIFO, first in,
first out, the opposite of a stack. A plain Python list can do this with
append + pop(0), but pop(0) shifts every remaining item left: O(n),
getting slower the longer the queue. collections.deque stores items in a
chain of small blocks so both ends are O(1) — the fix this lesson
builds around.

Queue up tracks for Tunebox's up-next list
The answer is right, but the mistake is not noticing what pop(0) costs to
get there — every remaining item shifts one slot left:
queue = ["A", "B", "C"]
first = queue.pop(0)
print(queue.index("C"))With 100,000 tracks waiting, one dequeue moves 99,999 items; serving the
whole queue that way moves about n²/2 items. deque ("deck") fixes it —
neither end ever shifts anything:
❓ Cross-question — "So why not use a deque for everything?" Fast ends cost a slow middle.
q[i]is O(n) near the middle of a deque, where a list is O(1), and a deque can't be sliced. Index into it → list; work at the ends → deque.