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:
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.
--
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
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