0

I have a list of dicts which are guaranteed to have the same keys. Each element of a dict is a list. What's the most elegant way to merge these dicts into one dict extending the lists of the same keys?

I have:

[
    {
        'x': ['a', 'b'],
        'y': ['c', 'd']
    },
    {
        'x': ['e', 'f'],
        'y': ['g', 'h']
    },
]

I want:

{
    'x': ['a', 'b', 'e', 'f'],
    'y': ['c', 'd', 'g', 'h']
}
goedwig
  • 351
  • 1
  • 2
  • 11

0 Answers0