I have 2 dictionaries with identical keys.
d1 = {'Dog':[7,2],'Cat':[5,2]}
d2 = {'Dog':1,'Cat':4}
Is there a good way of combining them so that I can have one dictionary that looks like this?
d = {'Dog':[7,2,1],'Cat':[5,2,4]}
I have 2 dictionaries with identical keys.
d1 = {'Dog':[7,2],'Cat':[5,2]}
d2 = {'Dog':1,'Cat':4}
Is there a good way of combining them so that I can have one dictionary that looks like this?
d = {'Dog':[7,2,1],'Cat':[5,2,4]}
for key, value in d2.iteritems():
if key in d1:
d1[key].append(value)
If one contains lists and the other contains ints, you can do:
d = {key:[d2[key]] + d1[key] for key in d1}