list1=[1,2,3]
list2=[4,5,6]
list3=[list1,list2]
print(list3)
list1.pop()
print(list3)
Output : [ [1,2,3] , [4,5,6] ]
[ [1,2] , [4,5,6] ]
list1=[1,2,3]
list2=[4,5,6]
list3=[list1,list2]
print(list3)
list1.pop()
print(list3)
Output : [ [1,2,3] , [4,5,6] ]
[ [1,2] , [4,5,6] ]
Your list3
refers directly to the memory from list1
and list2
. You perhaps want
list3 = [[...list1], [...list2]]
Edit, woops, wrong language, but same problem.
list3 = [list1.copy(), list2.copy()]