A coworker recently wrote a program in which he used a Python list as a queue. In other words, he used .append(x)
when needing to insert items and .pop(0)
You won't run out of memory using the list
implementation, but performance will be poor. From the docs:
Though
list
objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs forpop(0)
andinsert(0, v)
operations which change both the size and position of the underlying data representation.
So using a deque
will be much faster.