preferred syntax for list extend?

Ante abagaric at rest-art.hr
Wed Apr 17 04:01:48 EDT 2002


<bvdpoel at uniserve.com> wrote in message
news:3CBCC196.466476CE at uniserve.com...
>
> Just doing a bit of fooling around and I've found that if:
>
> q1=[1,2,3,4]
> q2=[5,6,7,8]
>
> then:
>
> q1 += q2
>
> is about 15% faster than
>
> q1.extend(q2)
>
> Mind you, my test was with a relatively short list, don't know if longer
> lists would act differently.
>
> I would have thought that using extend() would be preferred and faster?

Even if it was faster, I would still prefer +=.
foo.extend(yada) doesn't look beautiful to me at all.
After all, why do we have, e.g. == operator so we can say if a == b and
not a.equals(b)? Because the former is simply better looking, and to me the
same applies to += versus .extend() or even .append()







More information about the Python-list mailing list