Possible Duplicate:
Strange behavior of lists in python
I am attempting to initialize a 6 by 6 2D array of None. Here is what I do:
arr = [[None]*6]*6
Then I attempt to insert some values as follows:
arr[2][0] = arr[2][1] = 0
Which instead of changing the values of (2,0) and (2,1) to 0 and keeping the rest of the array full of None, it changes all the columns 0 and 1 to 0.
Full example:
>>> arr = [[None]*6]*6
>>> arr
[[None, None, None, None, None, None], [None, None, None, None, None, None], [None, None, None, None, None, None], [None, None, None, None, None, None], [None, None, None, None, None, None], [None, None, None, None, None, None]]
>>> arr[2][0] = arr[2][1] = 0
>>> arr
[[0, 0, None, None, None, None], [0, 0, None, None, None, None], [0, 0, None, None, None, None], [0, 0, None, None, None, None], [0, 0, None, None, None, None], [0, 0, None, None, None, None]]
Why does this happen and how can I prevent it?
p.s. my use of the phrase 'weird behavior' implies weird to me, not python messing up :)