+ 1
Dictionary
i have 2 dic, a and b a = {'a':100, 'b':200, 'c':300} b = {'a':300, 'b':200, 'd':400} i want to create new dic, dic c how to create dic c, if key in a and b same, value will be added, like this: c = {'a':400, 'b':400, 'c':300, 'd':400}
2 Antworten
+ 4
c = {'a': a['a'] + b['a'], 'b': a['b'] + b['b'], 'c': a['c'], 'd': b['d']} should work. Unless you want to use a for loop. 😉