What’s going on? lst2 contains lst1, which is being modified. Inside lst2, there is the underlying lst1 object, which is mutable. When you mutate it, with append(), you’re doing nothing to lst2, but it changes appearance because what’s inside has changed.
You probably want distinct lists. In that case, you can use the copy() method of list objects, which constructs a new list with the same elements. The difference with the original list is that if you change the original, the new list doesn’t change, it is independent.
lst1 = []
lst2 = []
for i in range(2):
lst1.append(i)
for j in range(3):
lst2.append(lst1.copy())
What Jean Abou Samra said is correct, and very good advice. The only
thing I would say is that instead of using the copy method it is more
Pythonic and slightly faster to use slicing to make the copy:
lst2.append(lst1.copy())
lst2.append(lst1[:]) # use slicing instead