I suggest you should build your list using a list comprehension:
>>>a = [[0]*3 for i in range(3)]
>>>a
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>>a[0][1] = 1
[[0, 1, 0], [0, 0, 0], [0, 0, 0]]
--
Steve R. Hastings"Vita est"
[EMAIL PROTECTED]http://www.blarg.net/~steveha
--
http://mail.python.
> if I do:
>
> a = [ [0] * 3 ] * 3
> a[0][1] = 1
>
> I get
>
> a = [[0,1,0],[0,1,0],[0,1,0]]
The language reference calls '*' the "repetition" operator. It's not
making copies of what it repeats, it is repeating it.
Consider the following code:
>>> a = []
>>> b = []
>>> a == b
True
>>> a is
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 w