Changing one element of a 2-D list in python
I have the following code:
a=[[0]*2]*3
print a
a[1][1]=2 print a
the output is: [[0,0],[0,0],[0,0]] [[0,2],[0,2],[0,2]]
Why is it changing all the elements of the list?
Shouldn't the output be:
[[0,0],[0,2],[0,0]]
What needs to be done if I just want to change one of the element?
Thanks for the help!
|