Combine Two Dictionaries Write a program to combine two dictionaries updating values for common keys. Input The first line of input will contain space-separated strings, denoting the keys of first dictionary. The second line of input will contain space-separated integers, denoting the values of first dictionary. The third line of input will contain space-separated strings, denoting the keys of second dictionary. The fourth line of input will contain space-separated integers, denoting the values of second dictionary. Output The output should be a single line containing the list of tuples of dictionary items with all the key-value pairs of two dictionaries sorted in ascending order by key.
keys_one = list(map(str, input().split(' ')))
values_one = list(map(int, input().split(' ')))
keys_two = list(map(str, input().split(' ')))
values_two = list(map(int, input().split(' ')))
result1 = [(i, j) for i in keys_one for j in values_one]
result2 = [(i, j) for i in keys_two for j in values_two]
result = result1 + result2
result = sorted(set(result))
print(result)
Comments
Leave a comment