Answer to Question #342576 in Python for sura karthik

Question #342576

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. 


1
Expert's answer
2022-05-18T15:26:04-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS