confused about resizing array in Python

John Machin sjmachin at lexicon.net
Sat Feb 3 17:36:28 EST 2007


On Feb 4, 7:41 am, "Ruan" <rds1... at sh163.net> wrote:
> Then how about Python's list?
>
> What is done exactly when list.append is executed?
>
> For list, is there another larger list initialized and the contents from the
> old list is copied to it together with the new appended list?
>

Qi ren you tian :-)

Llike with dictionaries, some spare space is left each time the list
is expanded, so over-all the amortised cost is O(n).

HTH,

John








More information about the Python-list mailing list