Merging Two Dicts On Common Keys With Values As A List
What do you do when you have two dicts like this
x = {'one': 1, 'three': 3, 'two': 2} y = {'one': 1.0, 'two': 2.0, 'three': 3.0}
and you need to combine them in such a way that the resultant dict will be something like this:
{'one': [1, 1.0], 'three': [3, 3.0], 'two': [2, 2.0]}
Here's a quick way of doing it:
result = dict(x.items() + y.items() + [(k, [x[k], y[k]]) for k in x.viewkeys() & y.viewkeys()])








