Okay, now that I've posted on python-list, and among the 80% of joke posts in my thread, there was a 20% of posts that assured me that Python's list has no such behavior and that I should use deque, I now ask on Python-ideas: Is there a good reason why `list.insert(whatever, 0)` doesn't opportunistically try to allocate more space at the left side of the list, so as to save the expensive operation of moving all the items? I'm not saying it should reserve space there, just check if that space is available, and if so use it. Is there any reason why not? Thanks, Ram. On Friday, February 7, 2014 1:58:49 AM UTC+2, Ram Rachum wrote:
Oops, my mistake, I meant to post in python-list but accidentally posted here because it was in my favorites. Sorry, I'll post there.
On Friday, February 7, 2014 1:58:05 AM UTC+2, Ram Rachum wrote:
Hi,
I'm curious. If I append an item to a list from the left using `list.insert`, will Python always move the entire list one item to the right (which can be super-slow) or will it check first to see whether it can just allocate more memory to the left of the list and put the item there, saving a lot of resources?
Thanks, Ram.