I want to create a list of dictionaries with the same index element from each list.
I have this dictionary:
d = {'name': ['bob', 'john', 'harry', 'mary'],
'age': [13, 19, 23],
'height': [164, 188],
'job': ['programmer']}
The desired output is:
d2 = [{'name': 'bob', 'age': 13, 'height': 164, 'job': 'programmer'},
{'name': 'john', 'age': 19, 'height': 188},
{'name': 'harry', 'age': 23},
{'name': 'mary'}]
I have tried something like this:
d2 = [dict(zip(d, t)) for t in zip(*d.values())]
But my output is:
d2 = [{'name': 'bob', 'age': 13, 'height': 164, 'job': 'programmer'}]
I think this is happening because the lists have different lengths.