My List of dict is below
file = [{'key': 'apple', 'type':'fruit'},
{'key': 'beans', 'type':'vegetable'},
{'key': 'beans', 'type':'fruit'}]
Expected out
- value of key is the new key
- value of type is new value
{'apple': 'fruit', 'beans':['vegetable','fruit']}
code is below
super_dict = {}
for d in file:
for l, m in d.items():
super_dict.setdefault(l, []).append(m)
super_dict
My out {'key': ['apple', 'beans', 'beans'], 'type': ['fruit', 'vegetable', 'fruit']}