I came across an issue in python appending to a list. The code I implemented was:
a=[1,2]
b=[3,4]
a.append(b)
b.append(5)
print a
print b
My understanding of python append was that the expected output of this code would be:
Expected Output
a=[1,2,[3,4]]
b=[3,4,5]
But the actual output is something different. Actual Output
a=[1,2,[3,4,5]]
b=[3,4,5]
I just want to know why this happened.
Since I appended the list b
to a
, before appending 5
to b
, list a
should have [1,2,[3,4]]