list.pop(0) vs. collections.dequeue

Steve Howell showell30 at
Sat Jan 23 10:27:12 CET 2010

On Jan 23, 12:13 am, Terry Reedy <tjre... at> wrote:
> On 1/23/2010 12:58 AM, Steve Howell wrote:
> > I really want to use list *normally* with all its perfectly good
> > semantics and reasonable implementation, except for its blind spot
> > with respect to popping the first element off the list.
> It was not designed for that. .pop() was added to lists about 10 years
> ago because I asked for it (with no parameter, pop off end only) and
> wrote what would now be a PEP -- and because Tim Peters later supported
> the idea. Adding the optional parameter was something of an afterthought
> (never publicly discussed as far as I know) for occasional use for
> 'short' lists where O(n) is tolerable. You have half persuaded me that
> that the parameter addition was a mistake. Perhaps is is too attractice
> a nuisance for some people ;=).

pop(0) is a useful idiom in parsers.  You can see examples in
ElementTree and lib2to3.

Even without pop(0), people would still write code like this, found in

            arg = args[0]
            args = args[1:]

It is sometimes overkill (and even inappropriate) to use a queue when
really you just want a list.  Iterators are great, but they also have
slightly different semantics than the list itself.

There is nothing wrong with a language specification that allows users
to do insert, delete, and pop on a list.  Once you freeze the language
specification, then you can turn your attention to improving the

More information about the Python-list mailing list