mardi 26 juillet 2016

Adding values associated with the same key in two different dictionaries

I've looked through a few of the questions here and none of them seem to be exactly my problem. Say I have 2 dictionaries, and they are dict1

{'A': 25 , 'B': 41, 'C': 32}

and dict2

{'D':21, 'A': 12, 'B':62}

I'm writing a program where I need to add the values associated with the same key. So like this:

{'A': [25 + 12], 'B': [41 + 62], 'C': [32], 'D': [21]}

Aucun commentaire:

Enregistrer un commentaire