concise code (beginner)

Alex Martelli aleax at mac.com
Mon Sep 10 01:11:09 EDT 2007


bambam <david at asdf.asdf> wrote:

> > O(n) to find the element you wish to remove and move over
> > everything after it,
> 
> Is that how lists are stored in cPython? It seems unlikely?

So-called "lists" in Python are stored contiguously in memory (more like
"vectors" in some other languages), so e.g. L[n] is O(1) [independent
from n] but removing an element is O(N) [as all following items need to
be shifted 1 place down].


Alex



More information about the Python-list mailing list