I was trying to create a 3x3 list of lists, and came up with this surprising behaviour:
# creating a 2D list with an overloaded * operator
mlist3 = [[0]*3]*3
print mlist3 # [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
mlist3[0][0] = 1
print mlist3 # [[1, 0, 0], [1, 0, 0], [1, 0, 0]] oops!
# populate it properly, now it works!
mlist3[0] = [7, 12, 23]
mlist3[1] = [22, 31, 9]
mlist3[2] = [4, 17, 31]
print mlist3 # [[7, 12, 23], [22, 31, 9], [4, 17, 31]]
mlist3[0][0] = 1
print mlist3 # [[1, 12, 23], [22, 31, 9], [4, 17, 31]]
Any explanation?