the most efficient method of adding elements to the list

K.S.Sreeram sreeram at tachyontech.net
Tue Jun 6 06:49:09 CEST 2006


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 add a bunch of items in one call.. you should use the
'extend' method.

Regards
Sreeram

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20060606/3db9d797/attachment.sig>


More information about the Python-list mailing list