the most efficient method of adding elements to the list

Girish Sahani girish at cse.iitb.ac.in
Tue Jun 6 00:38:21 EDT 2006


> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>




More information about the Python-list mailing list