- Write a Python program to combine two dictionary adding values for common keys. d1 = {‘a’: 100, ‘b’: 200, ‘c’:300},d2 = {‘a’: 300, ‘b’: 200, ‘d’:400}
- Write a Python program to find the highest 3 values of corresponding keys in a dictionary.
Write a Python program to combine two dictionary adding values for common keys. d1 = {‘a’: 100, ‘b’: 200, ‘c’:300},d2 …
Share
d1 = {‘a’: 100, ‘b’: 200, ‘c’:300}
d2 = {‘a’: 300, ‘b’: 200, ‘c’:400}
print(“Dictionary 1 is : \n”, d1, “\n”)
print(“Dictionary 2 is : \n”, d2, “\n”)
l1 = len(d1)
l2 = len(d2)
if l1 !=l2:
print(“Lengths of the two dictionaries are not equal.”)
for i in d2:
if i in d1:
d2[i] = d2[i] + d1[i]
else:
pass
print(“The sum of both the dictionaries is: \n”,d2)
Q1.Write a Python program to combine two dictionary adding values for common keys. d1 = {‘a’: 100, ‘b’: 200, ‘c’:300},d2 = {‘a’: 300, ‘b’: 200, ‘d’:400}
ANSWER: GO THROUGH BELOW LINK:
Q2.Write a Python program to find the highest 3 values of corresponding keys in a dictionary.
ANSWER: GO THROUGH BELOW LINK: