Could somebody give a explanation why the increment operation behave like following ?
>>> a = [ [0]*4 ] * 3
>>> print a
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
>>> a[1][1] += 1
>>> print a
[[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]]
I was expected a = [[0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 0]]
I understand that numpy.array
would give me expected result, but I really want to know why nested list doesn't...