I'm just trying to change the value from a nested dictionary.
The first dictionary is empty and the second one is populated. When I'm trying to change the value of one of the item in the nested dictionary, also the value with the same key of the others items has been changed.
name = dict()
work = {"hour" : 4, "age":21}
name['bob'] = work
name['harry'] = work
name['bob']['hour'] = 7
Now I obtain this if i print the new name dictionary:
{'bob': {'hour': 7, 'age': 21}, 'harry': {'hour': 7, 'age': 21}}
I'd like to have this situation:
{'bob': {'hour': 7, 'age': 21}, 'harry': {'hour': 4, 'age': 21}}
Why does it change the hour from the dictionary of harry?
name['bob'] = work.copy()andname['harry'] = work.copy().It will pass the reference not the value.