8. Use deque for queue operations
Use collections.deque instead of a list when you need efficient queue operations from the left side.
Lists are optimized for appending and popping at the end, not at the front. deque makes the queue behavior explicit and keeps performance predictable as the queue grows.
8.1. Don’t do this
1queue = ['a', 'b', 'c']
2item = queue.pop(0)
8.2. Do this
1from collections import deque
2
3queue = deque(['a', 'b', 'c'])
4item = queue.popleft()