If you want to obtain all the unique keys present in at least one of the dictionaries you can use the union of sets:
>>> set(dic1) | set(dic2)
{'a', 'e', 'u', 'i'}
What you really want is to join both dictionaries and add the values, you can apply the union of sets together with dict.get
in a dictionary by compression:
dic1 = {'a': 2, 'e': 5, 'u': 1}
dic2 = {'a': 3, 'e': 2, 'i': 2}
res = {key: dic1.get(key, 0) + dic2.get(key, 0) for key in set(dic1) | set(dic2)}
>>> res
{'u': 1, 'a': 5, 'e': 7, 'i': 2}
The construction of the dictionary by compression is efficient, the problem is that iteration is required twice for each dictionary, in addition to the construction of a set for each and a final result of the union. This makes for extended dictionaries more efficient in terms of memory and at run time from a certain point iterate over each dictionary sequentially:
from collections import defaultdict
res = defaultdict(int)
for dict_ in (dic1, dic2):
for key, value in dict_.items():
res[key] += value
>>> res
defaultdict(<class 'int'>, {'a': 5, 'e': 7, 'u': 1, 'i': 2})
>>> dict(res)
{'a': 5, 'e': 7, 'u': 1, 'i': 2}