Are there performance concerns with popping from front of long lists vs. the end of long lists?

MRAB python at mrabarnett.plus.com
Sun Jun 22 14:16:18 EDT 2014


On 2014-06-22 19:03, python at bdurham.com wrote:
> Should I have any performance concerns with the index position used
> to pop() values off of large lists?
>
> In other words, should pop(0) and pop() be time equivalent operations
>  with long lists?
>
When an item is popped from a list, all of the later items (they are
actually references to each item) are moved down. Therefore, popping
the last item is fast, but popping the first item is slow.

If you want to pop efficiently from both ends, then a deque is the
correct choice of container.



More information about the Python-list mailing list