I have two dictionaries, and i would like to create a third where the values from number 1 becomes the keys in number 2 - i have searched alot but i think since my second dictionary is in a nested form i have not seemed to find an example. I am new to python, which maybe is why i have searched for the wrong things, and i hoped that posting here could help me solve it.
dict1 = {0: '123', 1: '456', 2:'789'}
dict 2 =
{0: [{'id': 'abcd',
'ocid': '134'},
{'id': 'efgh',
'ocid': '154'}],
1: {'id': 'rfgh',
'ocid': '654'},
{'id': 'kjil',
'ocid': '874'}],
2: {'id': 'bgsj',
'ocid': '840'},
{'id': 'ebil',
'ocid': '261'}]}
My desired output is:
dict3 =
{123: [{'id': 'abcd',
'ocid': '134'},
{'id': 'efgh',
'ocid': '154'}],
456: {'id': 'rfgh',
'ocid': '654'},
{'id': 'kjil',
'ocid': '874'}],
789: {'id': 'bgsj',
'ocid': '840'},
{'id': 'ebil',
'ocid': '261'}]} ```
[0:theredict3 = {dict1[k]: v for k, v in dict2.items()}…?int(dict1[k])for an exact match to OPs expected output :)