Search Queue

Gabriel Genellina gagsl-py at
Wed Jan 17 02:10:00 CET 2007

At Tuesday 16/1/2007 15:01, Dennis Lee Bieber wrote:

>         If "Queue like functionality" means inserting at the end, and
>removing from the front... Just use a list

Someone said that time complexity should be part of an object public 
interfase. Implementing a queue using Python lists is trivial in 
terms of lines of code needed, but has a big time penalty. Queue 
users expect that put() and get() were fast, O(1) operations, but 
list.pop(0) is O(n).
Python>=2.4 has a deque class (in the collections module) that can be 
used as a simple queue, and is efficient both in time and memory used.

Gabriel Genellina
Softlab SRL 


Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 

More information about the Python-list mailing list