Never use pop(0) as a queue
transcript
A Python list can be a queue. Pop at zero removes the front. Looks harmless. Count what it moves.
Here is a queue of four values. Pop at zero removes twelve. Seven slides left. Then thirty. Then twenty five slides left. Three moves for one dequeue.
Say fifty thousand values wait. Every pop moves all the others. Draining the queue is over a billion moves. The same queue should cost fifty thousand.
A list keeps its values side by side. There can be no gap at the front. So every value must close the gap. That is one move for each value.
Use a deque. Its popleft takes one step. Or keep a head index. Move the index. Never shift the values. Both cost one step for any length.
Pop at zero shifts every value. Drain a long queue, and it crawls. Use a deque instead. Or a head index. Full breakdown in the lecture.