I want to merge the values of two dictionaries by their keys. Example:
d1 = {'a':1, 'b':2, 'c':3}
d2 = {'a':2, 'b':[2,3], 'd':3}
desired output:
{'a': [1, 2], 'b': [2, 2, 3], 'c': [3], 'd': [3]}
What I have so far is
d12 = {}
for d in (d1, d2):
for k,v in d.items():
d12.setdefault(k, []).append(v)
which produces
d12 = {'a': [1, 2], 'b': [2, [2, 3]], 'c': [3], 'd': [3]}
not desired output.
I searched a bit on SO and found that this post answers my question if only it didn't throw up TypeError: can only concatenate tuple (not "int") to tuple.