Copying 2D lists in python
Posted
by SuperString
on Stack Overflow
See other posts from Stack Overflow
or by SuperString
Published on 2010-03-29T23:10:34Z
Indexed on
2010/03/29
23:13 UTC
Read the original article
Hit count: 280
python
Hi I want to copy a 2D list, so that if I modify 1 list, the other is not modified.
For 1 D 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 2D list:
a = [[1,2],[3,4]] b = a[:]
If I modify b, a gets modified as well.
How do I fix this?
© Stack Overflow or respective owner