I am trying to handle values from two different dictionaries in Python. What I need to do is operate with values which have the same key in both dictionaries.
For instance, if dictionaries are:
d1 = {1:30, 2:20, 3:30, 5:80}
d2 = {1:40, 2:50, 3:60, 4:70, 6:90}
I need to add values from keys 1
, 2
and 3
from each dictionary.
I am trying to make an iterable of values, but, when I try to extend an empty iterable with values with a line such as:
sameKeys.extend(d1[i]))
I get an Error Key. I have tried many differents syntax but none has worked.