List of lists changes reflected across sublists unexpectedly
In Python, when you create a list of lists and modify one of the sublists, the change is reflected in all other sublists as well because they are all pointing to the same object in memory.
In Python, when you create a list of lists and modify one of the sublists, the change is reflected in all other sublists as well because they are all pointing to the same object in memory. This is known as a "shallow copy" of the list of lists.
Here is an example:
Shallow copy in Python
As you can see, the change made to the first sublist of the copied_list is reflected in the original_list as well.
To make a true copy of the list of lists, you should use the copy.deepcopy() function from the copy module.
Deep copy in Python
Now, changes made to the sublists of the copied_list do not affect the original_list