array = []
matrix = []
x = 0
while(x < 3):
array.append(".")
x += 1
x = 0
while(x < 3):
matrix.append(array)
x += 1
output:
[['.', '.', '.'], ['.', '.', '.'], ['.', '.', '.']]
when I try to change for instance matrix[0][1] to become "x" it changes the position in all the inner arrays. Can someone explain why?
example:
matrix[0][1] = "x"
output:
[['.', 'x', '.'], ['.', 'x', '.'], ['.', 'x', '.']]