'Reuniting two dictionaries with key-value in common
I have two dictionaries and i want to compare them based on the supporterId key like so:
dict1 = [{'name': 'John', 'supporterId': 1}, {'name': 'Paul', 'supporterId': 2}]
dict2 = [{'dependent': 'Erick','supporterId': 2}, {'dependent': 'Anna', 'email': '[email protected]', 'supporterId': 2}, {'dependent': 'George','email': '[email protected]',supporterId': 13}]
and I need to check if the supporterId between dict1 and dict2 are equal and if so put the name_dependent inside the corresponding supporterId in a so for example the output to this should be:
dict3 = {'name': 'Paul', 'supporterId': 2, 'dependent_name': ['George', 'Anna'], dependent_email: ['[email protected]', '[email protected]']}]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
