Queues and priority queues
Learn in depth →deque supports both ends; heapq keeps the smallest item at the root of a list-based min-heap.
deque.append; deque.popleft; heappush; heappopExample
from collections import deque
from heapq import heappush, heappop
q = deque([1, 2]); q.append(3)
heap = []; heappush(heap, 8); heappush(heap, 2)
print(q.popleft(), heappop(heap))Result
1 2
Watch for: A heap is not a globally sorted list. Repeated heappop operations retrieve items in priority order.
Practise this topic →