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

2014-06-22 Thread MRAB

On 2014-06-22 19:03, pyt...@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.
--
https://mail.python.org/mailman/listinfo/python-list


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

2014-06-22 Thread Terry Reedy

On 6/22/2014 2:03 PM, pyt...@bdurham.com wrote:

Should I have any performance concerns with the index position used to
pop() values off of large lists?


Yes. While performance is generally not part of the language 
specification, in CPython seq.pop(i) is O(len(seq)-i)



In other words, should pop(0) and pop() be time equivalent operations
with long lists?


No. If you want this, use collections.deque.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


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

2014-06-22 Thread Ethan Furman

On 06/22/2014 11:03 AM, pyt...@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?


I believe lists are optimized for adding and removing items from the end, so anywhere else will have an impact.  You'll 
have to do measurements to see if the impact is worth worrying about in your code.


--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


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

2014-06-22 Thread python
MRAB, Terry, Ethan, and others ...

Thank you - collections.deque is exactly what I was looking for.

Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list