[Tutor] Sequential assignment to list subscripts
alan.gauld@bt.com
alan.gauld@bt.com
Sun Nov 3 18:24:01 2002
> >>>> a=b=[0]
>
> Oops. That set a and b to refer to the same list in memory...
Correct, well done for figuring it out.
> I'll get that referencing eventually. Is there a handy way set a
> bunch of variables to *copies* of the same thing?
This isn't perfect but you can do this:
>>> a,b,c = tuple([7] * 3)
>>> a,b,c
7, 7, 7
>>>
ie put the value in a list, multiply by the number you require then
do a tuple asignment on the result.
HTH
Alan G