The Voidspace Techie Blog

Gravatar In CPython, += on lists is an in-place operation, and += and extend is exactly the same operation (+= is even a bit faster, since operator dispatch is faster than method lookups).

Or in other words, the following should not raise an assertion error:

>>> a = []
>>> b = a
>>> a += [1]
>>> assert a == b


</F>


Gravatar Right. I think *sometimes* we used the idiom :

someList += [item]

When we should have just used append (code pre-dating my arrival I hasten to add).

It is probably from changing these that we got the speed benefit from.

It's good to know that the inplace operations on Python lists are efficient. I wonder if that is guaranteed with IronPython ? I exect it is.


Name:

Email:

URL:

Comment:  ? 

 

Commenting by HaloScan