I can not understand why this is happening:
A = [[1,0], [2,2]] B = list(A) print('start A:', A, 'start B:', B) A[0][0] = 999 print('end A:', A, 'end B:', B)
This returns:
start A: [[1, 0], [2, 2]] start B: [[1, 0], [2, 2]] end A: [[999, 0], [2, 2]] end B: [[999, 0], [2, 2]]
Lists A and B become the same, although I explicitly copied B from A. This only happens when I do something like A [0] [0] = 999; if I replaced it with A [0] = 999, then A and B differ at the end.
What is the reason for this, and is there a way to change A in this way without affecting B?
source share