Negative array indicies and slice()

Ian Kelly ian.g.kelly at gmail.com
Mon Oct 29 19:07:53 EDT 2012


On Mon, Oct 29, 2012 at 9:42 AM, Andrew Robinson
<andrew3 at r3dsolutions.com> wrote:
> The list was generated in a single pass by many .append() 's, and then
> copied once -- the original was left in place; and then I attempted to slice
> it.

Note that if the list was generated by .appends, then it was copied
more than once.  Python reserves a specific amount of space for the
list.  When it grows past that, the list must be reallocated and
copied.  It grows the list exponentially in order to keep the
amortized time complexity of append at O(1), but the point is that a
list of 20 million items is going to be resized and copied several
times before it is complete.



More information about the Python-list mailing list