[Tutor] why is list.pop(0) slow?

Magnus Lyckå magnus@thinkware.se
Wed Jun 18 21:31:38 2003


At 00:32 2003-06-19 +0800, Wari Wahab wrote:
>Is it really that bad?

Worse if you increase the size of the list... But isn't
is still fairly fast?

>Performance improved when the list i have is reversed and used pop().

Yes, then you just need to restructure the list once.

A Python list is not a linked list, it's much more like a
vector or array in other languages. (In C++ STL, I think
the closest fit is a vector.)

If you have an application where this matters you might want
to consider other implementations. Obviously, the .reverse()
strategy won't be of any help if you alternate between pushing
and popping as is common with queues.

The Python cookbook as ASPN contains some examples of rings that
might be useful.


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language