Skip to content
Advertisement

Merging values with a same key

Tried to google how to merge multiple dictionaries, but could not find a solution to merge values under same key in a dictionary. Although the original data is list, the expected results should be dictionary. I am stacked here, and hope someone show me a way to get resolve this.

Original Data:

JavaScript

Expected Results:

JavaScript

Advertisement

Answer

You can do this by looping over the lists and dictionaries. Like this:

JavaScript

This will also work for dictionaries with multiple keys, unlike the other answer.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement