May-19-2020, 12:16 PM
Hey everyone, I an new in Python and I want to update an item of a matrix, but 3 items are updated. I am not sure why this happens.
Please check the following code:
Please check the following code:
Board = [] rows = ["_" for i in range(3)] for index in range(3): Board.append(rows) Board[0][0] = "1" print(Board)The current Output is:
[['1', '_', '_'], ['1', '_', '_'], ['1', '_', '_']]The expected Output should be:
[['1', '_', '_'], ['_', '_', '_'], ['_', '_', '_']]