list addition methods compared.
Ishwor
ishwor.gurung at gmail.com
Sun Dec 26 18:17:08 EST 2004
On Sun, 26 Dec 2004 04:57:17 -0500, Terry Reedy <tjreedy at udel.edu> wrote:
>
> "Ishwor" <ishwor.gurung at gmail.com> wrote in message
> news:34534aed0412252012638c85fd at mail.gmail.com...
> > Hi all
> > I have just wrote a small script to compare the speed of list addition
> > methods.
>
> There are two meanings of 'list addition':
>
> li = li+[item] *copies* the list and adds item
>
> li += [item] is the same as li.extend([item]) which add item to the end of
> the list *without* copying.
>
> Of course, extending a list is faster than copying + one more.
>
I agree with you that list extending is faster way to add as compared
to method 1. also that method 2 is mapped to 'extend()' anyway, but
why is the method 3 ( l3.extend() ) in my example code talking only
nearly 1% of time to complete as compared to method 1/2??? I think
there is a problem with the code but i don't see where. :-(
> Terry J. Reedy
Thanks Terry for yet another small (really small) step towards enlightment.
[snip]
--
cheers,
Ishwor Gurung
More information about the Python-list
mailing list