In [1]: from collections import defaultdict
In [2]: dict1 = {"a1": "a2", "a2": "a3", "a3": "a5"}
...: dict2 = {"a1": "a4", "a2": "a5"}
In [3]: dd = defaultdict(list)
In [4]: for key in set(list(dict1.keys())+list(dict2.keys())):
...: if key in dict1:
...: dd[key].append(dict1[key])
...: if key in dict2:
...: dd[key].append(dict2[key])
...:
In [5]: dd
Out[5]: defaultdict(list, {'a2': ['a3', 'a5'], 'a1': ['a2', 'a4'], 'a3': ['a5']})