the most efficient method of adding elements to the list

Erik Max Francis max at alcyone.com
Tue Jun 6 00:39:03 EDT 2006


alf wrote:

> Would it be .append()? Does it reallocate te list with each apend?
> 
> l=[]
> for i in xrange(n):
>       l.append(i)

No, it doesn't.  It expands the capacity of the list if necessary.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   It isn't important to come out on top, what matters is to be the one
   who comes out alive. -- Bertolt Brecht, 1898-1956



More information about the Python-list mailing list