If I do:

a = [ [0,0,0], [0,0,0], [0,0,0] ]
a[0][1] = 1

I get:

a = [ [0,1,0],[0,0,0],[0,0,0] ]

as expected

But if I do:

a = [ [0] * 3 ] * 3
a[0][1] = 1

I get

a = [[0,1,0],[0,1,0],[0,1,0]]

AFAIC, "*" is supposed to generate multiple copies of the given token.
Therefore I thought both cases would be the same, but they are not.

Can anyone explain to me what exactly is going on in the second case?

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to