Complexity question on Python 3 lists

Chris Rebert clp2 at
Wed Feb 15 19:35:25 CET 2012

On Wed, Feb 15, 2012 at 10:20 AM, Franck Ditter <franck at> wrote:
> What is the cost of calling primes(n) below ? I'm mainly interested in
> knowing if the call to append is O(1), even amortized.
> Do lists in Python 3 behave like ArrayList in Java (if the capacity
> is full, then the array grows by more than 1 element) ?

Yes. Python lists aren't linked lists. list.append() resizes the
underlying array intelligently to give O(1) performance, although I
can't find any guarantee of this in the docs, but it is true in
practice for all major Python implementations.


More information about the Python-list mailing list