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

Jon Ribbens jon+usenet at unequivocal.co.uk
Thu Mar 24 11:25:56 EDT 2016


On 2016-03-24, BartC <bc at freeuk.com> wrote:
> On 24/03/2016 15:03, Jon Ribbens wrote:
>> On 2016-03-24, BartC <bc at freeuk.com> wrote:
>>> On 24/03/2016 14:08, Jon Ribbens wrote:
>>>> if you thought you needed to do that then most likely what you
>>>> should actually be doing is re-writing your code so you no longer
>>>> need to. However, you could do:
>>>>
>>>>     L[:] = [0] * len(L)
>>>
>>> OK, but that's just building a new list as I've already mentioned.
>>
>> 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)'? (And which would briefly require twice the memory occupied 
> by the old list, if I'm not mistaken.)

It's replacing them with elements from an entirely new list, which is
then discarded, and only the original list remains.



More information about the Python-list mailing list