+ 1
why the answer is wrong?!
why in this code, 't' will be changed? S = [[511 for i in range(3)] for j in range(3)] t = S.copy() S[0][2] = 76 print(t)
4 Antworten
+ 6
Because t is just another label that is attached to the same list. Changing S changes t as well. To create an independent list, use deepcopy:
from copy import deepcopy
S = [[511 for i in range(3)] for j in range(3)]
t = deepcopy(S)
+ 3
What answer are you reffering to?
Please add more informations to your question.
+ 1
@Anna tell me more about 'list.copy()' and its properties.
+ 1
@Dragonxiv, I want a backup of my list, but it'll be changed.