I have a global list (of lists) variable. I send a shallow copy of the global list to another function as a parameter.
Surprisingly, the original list gets changed when I remove some elements from the parameter within the invoked function.
Can someone please tell me why it's happening and how to prevent this from happening?
Here is the simplified code example:
def saveCandidateRoutes(candidateRoutes):
for route in candidateRoutes:
if route: # check if the list, 'route', is empty.
tweetId = route.pop(0)
stanox = route.pop(-1)
....
def main():
global allCandidatePaths
copyOfAllCandidatePaths= list(allCandidatePaths) # making a deep copy
result = saveCandidateRoutes(copyOfAllCandidatePaths)