I have declared a (5x6) list called path in Python as:
path = [[' ']*6]*5
Now, when I change the value of any one element as:
path[4][5] = '*'
or
path[0][5] = '*'
I get the output as:
[' ', ' ', ' ', ' ', ' ', '*']
[' ', ' ', ' ', ' ', ' ', '*']
[' ', ' ', ' ', ' ', ' ', '*']
[' ', ' ', ' ', ' ', ' ', '*']
[' ', ' ', ' ', ' ', ' ', '*']
That is, all the elements of the specified column get changed to '*'. Why does this happen? My guess is that maybe this has something to do with the way this short-hand notation is implemented in Python. Maybe the interpreter takes the first row and copies it down for all columns.