First of all, I want to open the dictionary and change the dictionary key. I have tried using zip but it is not working as I want.
This is the data that I have,
data= [{'id': 'abc001',
'demo': [{'Answer': '1', 'QID': 'AB001'},
{'Answer': '6', 'QID': 'AB023'},
{'Answer': '3', 'QID': 'AB004'},
{'Answer': '3', 'QID': 'AB006'}]},
{'id': 'abc002',
'demo': [{'Answer': '1', 'QID': 'AB001'},
{'Answer': '6', 'QID': 'AB002'},
{'Answer': '3', 'QID': 'AB003'},
{'Answer': '3', 'QID': 'AB006'}]},
{'id': 'abc003',
'demo': [{'Answer': '1', 'QID': 'AB001'},
{'Answer': '6', 'QID': 'AB002'},
{'Answer': '3', 'QID': 'AB004'},
{'Answer': '3', 'QID': 'AB005'}]}]
I want to change the QID to another name BUT there are responses that have this QID and then another response has other QID as in data
This is the name that need to change for the QID:
QID
AB001-gender
AB002-edu
AB003-qual
AB004-area
AB005-sal
AB006-living
AB023-job
Hence, this is the output that I need : The dictionary only inside the demo.
Output=[{'id': 'abc001'
'demo':{'gender':'1',
'job':'6',
'area':'3',
'study':'3'}},
{'id': 'abc002'
'demo':{'gender':'1',
'edu':'6',
'qual':'3',
'living':'3'}},
{'id': 'abc003'
'demo':{'gender':'1',
'edu':'6',
'area':'3',
'sal':'3'}}]
You can just do this: