I want to copy a 2D list, so that if I modify one list, the other is not modified.
For a one-dimensional list, I just do this:
a = [1, 2]
b = a[:]
And now if I modify b
, a
is not modified.
But this doesn't work for a two-dimensional list:
a = [[1, 2],[3, 4]]
b = a[:]
If I modify b
, a
gets modified as well.
How do I fix this?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…