given the following list:
l=[1,2,3]
l2=l1[:]
l2[0]=10
print(l)
#[10,2,3]
How do I copy the original list and make changes on the copied list without changing the original list (without using copy.deepcopy(x)
)?
And another question,
if I can create l2
by assigning l1
to l2
why does the copy()
function exists? does it do anything differently?
l2=l1
l2=l1.copy()
The things that I tried to do are shown above.