I have this weird question about lists in python and how they actually work. As you see in the following code it is a pretty easy code. But what I expected to get as output is really different from what I really got
I expected to get:
l1 = [10,4,5]
l2 = [3,1,2,4,5]
l3 = [7,8]
But I got :
l1 = l2 = [10,1,2,4,5]
l3 = [7,8]
def insert(lst1,lst2,p):
if p>0:
lst1[p:p] = lst2
else:
lst1 = lst2
return lst1
l1 = [3,4,5]
l2 = insert(l1,[1,2],1)
l1[0] = 10
l3 = insert(l2,[7,8],0)
print(l1)
print(l2)
print(l3)
Can anyone please explain? thanks in advance