The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Random832 random832 at fastmail.com
Thu Mar 24 11:30:55 EDT 2016


On Thu, Mar 24, 2016, at 11:18, BartC wrote:
> On 24/03/2016 15:03, Jon Ribbens wrote:
> > No it isn't, it's replacing the elements in-place,
> 
> Replace them with what, if not an entirely new list built from 
> '[0]*len(L)'?

Well, the *contents* of such a list, obviously. But the original list's
contents are replaced, meaning that e.g. all other references to the
list remain valid etc.

> (And which would briefly require twice the memory occupied 
> by the old list, if I'm not mistaken.)

Sure, *briefly*. And if you really care about that, you can do L[:] = (0
for x in L); or itertools.repeat(0, len(L)).



More information about the Python-list mailing list