Mar-13-2022, 08:25 PM
I'm beginning to learn Python and I've come across a problem that is foreign to me as a past Lua programmer. I've noticed that after appending a variable to a list, if that variable changes value so does the value in the list as well, even though the list was never directly redefined.
Here's what I mean,
Here's what I mean,
currentPath = ["EWR", "JFK", "SFO"] completedPaths = [] completedPaths.append(currentPath) print(completedPaths) currentPath.clear() print(completedPaths)
Output:["EWR", "JFK", "SFO"]
[[]]
This confuses me because in Lua the list in completedPaths would stay the same until directly redefined, even if the variable it was once equated to has changed. How would I solidify the list inside of completedPaths while also changing the currentPath variable to input more values later on?