Как насчет этого?
#!/usr/bin/env python
from itertools import chain
dict1 = {'key_1': 10, 'key_2': 14, 'key_m': 321}
dict2 = {'key_1': 15, 'key_2': 12, 'key_m':2, 'key_n':34}
dict3 = {}
# Go through all keys in both dictionaries
for key in set(chain(dict1, dict2)):
# Find the key in either dictionary, using an empty
# string as the default if it is not found.
dict3[key] = [dict.get(key, "")
for dict in (dict1, dict2)]
print(dict3)
Теперь dict3
имеет список всех значений из входных массивов.
Или, если вы хотите, в этом [[key, value, value], [key, value, value]...]
формате:
#!/usr/bin/env python
from itertools import chain
dict1 = {'key_1': 10, 'key_2': 14, 'key_m': 321}
dict2 = {'key_1': 15, 'key_2': 12, 'key_m':2, 'key_n':34}
result = [[key] + [dict.get(key, "")
for dict in (dict1, dict2)]
for key in set(chain(dict1, dict2))]
result.sort()
print(result)