my_dict = {'index':[1,2,3], 'answer':['A','D','B']}
I want to convert this my_dict
into this below list
[{'index': 1,'answer': 'A'}, {'index':2, 'answer': 'D'}, {'index': 3, 'answer': 'B'}]
I have the solution but it depends upon pandas
library, but I am looking for a way to do it without any dependencies
pandas
solution:
import pandas as pd
output = list(pd.DataFrame(my_dict).T.to_dict().values())
output
[{'index': 1, 'answer': 'A'},
{'index': 2, 'answer': 'D'},
{'index': 3, 'answer': 'B'}]