Sorry to ask a silly question, but I can’t find a complete answer.
With the following:
a_dict = {"A":0, "B":0}
def GetElementRef(index):
return a_dict[index]
would_like_to_modify = GetElementRef("A")
would_like_to_modify = 2
This results in would_like_to_modify being given the value of 2, while a_dict remains unchanged.
AFAIK, any assignment based operation on would_like_to_modify just reseats the reference. Is there any way to modify the original dictionary element in this indirect way?
I am aware of a few other ways I can implement this by directly referring to the dictionary, but I’m curious if this can somehow be done.
For the code in the question, the answer is “no”, because the values in the dictionary are numbers, and numbers are immutable. On the other hand, if the values were mutable, they can indeed be changed. For example: