I created a dict of dicts in python.
dict1 = {}
dict2 = {'a': 0,
'b': 0,
'c': 0}
for i in range(1, 4):
dict1.update({i : dict2})
print(dict1)
output: {1: {'a': 0, 'c': 0, 'b': 0},
2: {'a': 0, 'c': 0, 'b': 0},
3: {'a': 0, 'c': 0, 'b': 0}}
I now want to change the value of 'a' in the first dictionary.
dict1[1]['a'] += 1
The output looks like this.
print(dict1)
output: {1: {'a': 1, 'c': 0, 'b': 0},
2: {'a': 1, 'c': 0, 'b': 0},
3: {'a': 1, 'c': 0, 'b': 0}}
All 'a' values changed and not just the one in the first dictionary. Why is that? And how do I change only the value in the first dict?