2.3 Python
2.3 Python
WORKSHEET 2.3
1. Aim:
Program to demonstrate creation, accessing of dictionary and apply different kinds of
operations on them.
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.
2. Source Code:
#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.
print("SAGAR ROHILLA 21BCS1383")
def highest_3_values_1(my_dict):
result_dict = {}
sorted_dict = sorted(my_dict.items(), key=lambda x: x[1], reverse=True)
for i in range(3):
result_dict[sorted_dict[i][0]] = sorted_dict[i][1]
return result_dict
my_dict = {'A': 67, 'B': 23, 'C': 45, 'D': 56, 'E': 12, 'F': 69}
print(highest_3_values_1(my_dict))
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
3. Screenshot of outputs:
OUTPUT_1
OUTPUT_2