How do I clone a list so that it doesn’t change unexpectedly after assignment?

With new_list = my_list, you don’t actually have two lists. The assignment just copies the reference to the list, not the actual list, so both new_list and my_list refer to the same list after the assignment. To actually copy the list, you have various possibilities: You can use the builtin list.copy() method (available since Python … Read more