I just noticed that declaring two empty lists as:
list1 = list2 = []
produced an entirely different result as compared to:
list1 = []
list2 = []
I don’t this problem is related to the whole program as such, or that the result is important. Nevertheless here is the whole program. So is there any difference between the two ways of declaration?
Assignes the same empty list instance (
[]) to both list1 and list2. This is because object instances are assigned by reference.You can do this instead:
to assign two different lists two the two variables.
You can check it as follows: