[Solved] How can I append items to a list without changing the original list [duplicate]


Variables in Python are just references. I recommend making a copy by using a slice. l_copy = l_orig[:]

When I first saw the question (pre-edit), I didn’t see any code, so I did not have the context. It looks like you’re copying the reference to that row. (Meaning it actually points to the sub-lists in the original.)

new_list.append(row[:])

2

solved How can I append items to a list without changing the original list [duplicate]