Re: the most efficient method of adding elements to the list

2006-06-06 Thread bruno at modulix
alf wrote: Hi, Would it be .append()? Does it reallocate te list with each apend? l=[] for i in xrange(n): l.append(i) dumb FWIW, you'd have the same result with: l = range(n) /dumb More seriously (and in addition to other anwsers): you can also construct a list in one path:

Re: the most efficient method of adding elements to the list

2006-06-05 Thread Girish Sahani
Hi, Would it be .append()? Does it reallocate te list with each apend? Yes it does. If order of the new element being added doesnt matter you can use append. If it does, you can use insert(). l=[] for i in xrange(n): l.append(i) Thx, A. --

Re: the most efficient method of adding elements to the list

2006-06-05 Thread Erik Max Francis
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 [EMAIL PROTECTED] http://www.alcyone.com/max/ San Jose, CA, USA 37 20 N 121

Re: the most efficient method of adding elements to the list

2006-06-05 Thread K.S.Sreeram
alf wrote: Would it be .append()? Does it reallocate te list with each apend? No append does NOT reallocate for every call. Whenever a reallocation happens, the newsize is proportional to the older size. So you should essentially get amortized constant time for every append call. If you want to