I have a nested dictionary, d1:
{'2020-12-10': {'EUR': 1.1379,
'JPY': 128.75,
'BGN': 1.9558,
'CZK': 25.845,
'DKK': 7.4641,
'GBP': 0.90228},
'2020-12-09': {'EUR': 1.1354,
'JPY': 128.31,
'BGN': 1.9558,
'CZK': 25.886,
'DKK': 7.463,
'GBP': 0.88885},
'2020-11-08': {'EUR': 1.1409,
'JPY': 129.04,
'BGN': 1.9558,
'CZK': 26.002,
'DKK': 7.4617,
'GBP': 0.89108}}
and I want to change it into this format:
d2 = [{'date': '2020-12-10', 'target_currency': 'EUR', 'exchange_rate' : 1.1379},
{'date': '2020-12-09', 'target_currency': 'EUR', 'exchange_rate' : 1.1354},
...
]
(which I need to convert later in a line-delimited json file, using json.dumps()).
I have tried this as a first step, which gets the date as a key.
d2 = {}
for k, v in d1.items():
key = k
d2[key] = {"date": k}
d2[key].update({k_:v_ for k_, v_ in v.items()})
d2
{'2020-12-10': {'date': '2020-12-10',
'EUR': 1.1379,
'JPY': 128.75,
'BGN': 1.9558,
'CZK': 25.845,
'DKK': 7.4641,
'GBP': 0.90228},
Need some pointers how to go from here. thank you.