list.pop(0) vs. collections.dequeue

Ethan Furman ethan at
Tue Jan 26 01:25:31 CET 2010

Steve Howell wrote:
>> On Sat, 23 Jan 2010 09:57:04 -0500, Roy Smith wrote:
>>> So, we're right back to my statement earlier in this thread that the
>>> docs are deficient in that they describe behavior with no hint about
>>> cost. Given that, it should be no surprise that users make incorrect
>>> assumptions about cost.

No hint?  Looking at the below snippet of docs -- "not efficient" and 
"slow" sound like pretty good hints to me.

> Bringing this thread full circle, does it make sense to strike this
> passage from the tutorial?:
> '''
> It is also possible to use a list as a queue, where the first element
> added is the first element retrieved (“first-in, first-out”); however,
> lists are not efficient for this purpose. While appends and pops from
> the end of list are fast, doing inserts or pops from the beginning of
> a list is slow (because all of the other elements have to be shifted
> by one).
> '''
> I think points #3 and #6 possibly apply. Regarding points #2 and #4,
> the tutorial is at least not overly technical or specific; it just
> explains the requirement to shift other elements one by one in simple
> layman's terms.

I think the paragraph is fine.  Instead of waiting for the (hundreds 
of?) posts wondering why making a FIFO queue from a list is so slow, and 
what's wrong with Python, etc, etc, it points out up front that yes you 
can, and here's why you don't want to.  This does not strike me as too 
much knowledge.


More information about the Python-list mailing list