You can make a copy of your list
>>> x = [1, 2, 3] >>> y = list(x) >>> y.append(4) >>> y [1, 2, 3, 4] >>> z = list(x) >>> z.append(5) >>> z [1, 2, 3, 5]
or use concatenation that will make a new list
>>> x = [1, 2, 3] >>> y = x + [4] >>> z = x + [5] >>> y [1, 2, 3, 4] >>> z [1, 2, 3, 5]
The former is probably more moving idiomatic / general, but the latter works just fine in this case. Some people also copy using truncation ( x[:] creates a new list with all the elements of the original x list) or the copy module. None of them are terrible, but I find the former to be mysterious and the latter a little stupid.
source share