Info Node: (python2.1-tut.info)Using Lists as Queues
(python2.1-tut.info)Using Lists as Queues
Using Lists as Queues
---------------------
This manual section was written by Ka-Ping Yee <ping@lfw.org>.
You can also use a list conveniently as a queue, where the first
element added is the first element retrieved ("first-in, first-out").
To add an item to the back of the queue, use `append()'. To retrieve
an item from the front of the queue, use `pop()' with `0' as the index.
For example:
>>> queue = ["Eric", "John", "Michael"]
>>> queue.append("Terry") # Terry arrives
>>> queue.append("Graham") # Graham arrives
>>> queue.pop(0)
'Eric'
>>> queue.pop(0)
'John'
>>> queue
['Michael', 'Terry', 'Graham']