I have a list of dictionaries in the following format:
foo = [
{'a': 'x', 'b': 'y', 'c': 'z'},
{'a': 'j', 'c': 'z'}
]
I want to group this list of dictionaries into a single dictionary, like:
bar = {
'a': ['x', 'j'],
'b': ['y', None],
'c': ['z', 'z']
}
What I've currently done is, looping through all the dicts in foo
and create a list of keys and then looping again over the same to create bar
. I wonder whether there is a simpler way to accomplish this. Can anyone help?