Adding item in front of a list

Michael Hudson mwh at python.net
Wed Apr 9 12:47:01 EDT 2003


Thomas Guettler <pan-newsreader at thomas-guettler.de> writes:

> insert(0, 1) behaves like insert(-1, 1). It is better, but
> insert(1) would be best. 
> 
> This is not about the functionality, but about the beauty of python.
> 
> Would be nice if handling lists like queues and stacks would be a bit
> better. 

Ah, but Python is telling you something here: if you want to use a
list as a stack, you should push/pop from the *end* to reduce the
number of allocations...

Cheers,
M.

-- 
  ... with these conditions cam the realisation that ... nothing
  turned a perfectly normal healthy individual into a great political
  or military leader better than irreversible brain damage.
                   -- The Hitch-Hikers Guide to the Galaxy, Episode 11




More information about the Python-list mailing list