Here's a quick solution:
A = {1 : "one", 2 : "two"}
B = {2 : "dva", 3 : "three"}
d = {**A}
for k, v in B.items():
d[k] = [d[k], v] if k in d else v
print(d)
Output:
{1: 'one', 2: ['two', 'dva'], 3: 'three'}
Here's a more generalizable solution, that works with an indefinite number of dictionaries:
def cool_dict_merge(dicts_list):
d = {**dicts_list[0]}
for entry in dicts_list[1:]:
for k, v in entry.items():
d[k] = ([d[k], v] if k in d and type(d[k]) != list
else [*d[k], v] if k in d
else v)
return d
Testing:
>>> A = {1: "one", 2: "two"}
>>> B = {2: "dva", 3: "three"}
>>> C = {2: "chewbacca", 3: "ThReE", 4: "four"}
>>> D = {0: "zero", 4: "jack", 5: "five"}
>>> cool_dict_merge([A, B, C, D])
{1: 'one', 2: ['two', 'dva', 'chewbacca'], 3: ['three', 'ThReE'], 4: ['four', 'jack'], 0: 'zero', 5: 'five'}
Note that, as others pointed out, the result you're currently getting is probably more preferable in most scenarios, since it's more generalizable and easier to work with. We don't know about your use case though, so just use the method you feel most comfortable with.