I have this example:
d = {}
x = {'key1': 'value1', 'key2': 'value2'}
above = ['abovekey1', 'abovekey2']
for ak in above:
d[ak] = x
d[ak]['key2'] = str(ak)
The output of d is:
{'abovekey1': {'key1': 'value1', 'key2': 'abovekey2'},
'abovekey2': {'key1': 'value1', 'key2': 'abovekey2'}}
But I wrote the code to expect this output:
{'abovekey1': {'key1': 'value1', 'key2': 'abovekey1'},
'abovekey2': {'key1': 'value1', 'key2': 'abovekey2'}}
How can I change the code to yield the output that I am expecting and what am I missing in the above example?
Thank you all!