Copyright (C) 2000-2012 |
GNU Info (python2.1-tut.info)Using Lists as QueuesUsing 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'] automatically generated by info2www version 1.2.2.9 |