I have a list of dictionaries
ls1 = [{'AccountBalance': '78', 'Status': '0'},
{'AccountBalance': '56', 'Status': '1'},
{'AccountBalance': '34', 'Status': '0'},
{'AccountBalance': '12', 'Status': '0'}]
I would like to convert this to a dictionary of 2 dictionaries
dict1 = {'AccountBalance': {0: '78',
1: '56',
2: '34',
3: '12'},
'Status': {0: '0',
1: '1',
2: '0',
3: '0'}}
what would be the fastest way to do this?
pd.DataFrame(ls1).to_dict() works, but I want to know if something is a little faster?
>Solution :
A one-liner solution would be
dict1 = {key: {index: item[key] for index, item in enumerate(ls1)} for key in ls1[0]}