I have a list of strings and i’d like for each string in the list to store it in a dictionary and send it to another function. So far it looks like this:
list = ['75001', '75002', '75003']
params = {}
for elt in list:
params['elt'] = elt
...
foo(params)
But the problem is that i’m storing the reference to elt and not the value, so in my function calls i always have the last element of list:
params['elt'] = '75003'
How could i store only the value and not the reference ?
The problem is that all functions get the same dictionary. Try this instead:
Now each call to
foo()gets a new container and they can’t see each other anymore.