First of all please accept my apologize for this basic question If It was. I have a real coding issue but just for the example I'd like to show you the code above. I'd like to understand why the first code is acting asboardI
and board
were pointing on the same reference and how to make the first code only modify boardI
?
board = []
board.append(["0"] * 10)
boardI = list(board)
boardI[0].append("1")
print board
print boardI
>>[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1']]
>>[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1']]
board = []
board.append(["0"] * 10)
boardI = list(board)
boardI.append("1")
print board
print boardI
>>[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0']]
>>[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], '1']
If I had declared boardI
as boardI = board
I'd have undertood but since boardI = list(board)
it seems I missed something