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[:]
For a more general solution that works regardless of the number of dimensions, use copy.deepcopy():
copy.deepcopy()
import copy b = copy.deepcopy(a)
b = [x[:] for x in a]