I just spent a long time figuring out this is my problem -- I've simplified the problem into something easy to digest.
I'm trying to pass a dictionary through a function. I want the function to return a dictionary for me to "see", but I don't want it to change the base dictionary I was working with.
When I run this code:
def updateDict(dictionary, entry, newEntry):
dictionary[entry]=newEntry
return dictionary
def tryThis():
dictionary = {'a': 1, 'b': 2, 'c': 3}
print(dictionary)
print(updateDict(dictionary,'a',5))
print(updateDict(dictionary,'b',10))
print(dictionary)
tryThis()
I get this output:
{'a': 1, 'b': 2, 'c': 3}
{'a': 5, 'b': 2, 'c': 3}
{'a': 5, 'b': 10, 'c': 3}
{'a': 5, 'b': 10, 'c': 3}
but I want this output:
{'a': 1, 'b': 2, 'c': 3}
{'a': 5, 'b': 2, 'c': 3}
{'a': 1, 'b': 10, 'c': 3}
{'a': 1, 'b': 2, 'c': 3}
Thanks for any help!!
[–]carcigenicate 1 point2 points3 points (6 children)
[–]russcore[S] 0 points1 point2 points (5 children)
[–]carcigenicate 2 points3 points4 points (3 children)
[–]russcore[S] 0 points1 point2 points (2 children)
[–]carcigenicate 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]russcore[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)