Roulette wheel

Peter Otten __peter__ at web.de
Thu Mar 5 06:54:39 EST 2009


mattia wrote:

> Il Thu, 05 Mar 2009 10:46:58 +0100, Peter Otten ha scritto:
> 
>> mattia wrote:
>> 
>>>> Note how get_roulette_wheel() is now completeley independent of the
>>>> concrete problem you are using it for.
>>> 
>>> Ok, but also a lot more memory consuming ;-)
>> 
>> I don't think so. Python references objects; therefore the list
>> 
>> [tiny_little_thing]*N
>> 
>> does not consume more memory than

Oops, should have been less.

>> 
>> [big_fat_beast]*N
>> 
>> Or did you have something else in mind?
>> 
>> Peter
> 
> Ok, understood. So if I have e.g. [[200 elements]]*N, then I'll have N
> pointers to the same location of my seq, right?

Right. You can verify this with

>>> v = [0]
>>> items = [v]*5
>>> v[0] = 42
>>> items
[[42], [42], [42], [42], [42]]

which often surprises newbies.

Peter



More information about the Python-list mailing list