Question about `list.insert`
Terry Reedy
tjreedy at udel.edu
Thu Feb 6 19:40:00 EST 2014
On 2/6/2014 6:59 PM, cool-RR 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?
"It depends on the implementation"
Assume O(n), which I am sure it is for CPython, but easy enough to check.
--
Terry Jan Reedy
More information about the Python-list
mailing list