You are on page 1of 2

PRACTICAL NO.

Name: Pranav Sandip Wadge. dic1.update(dic2)

Roll_No:03. dic1.update(dic3)

Branch: TYCO. print(dic1)

==================================== OUTPUT:

1. Write a Python script to sort (ascending {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
and descending) a dictionary by value.
====================================
asc_dec = {'Suyash': 9 'Aranav': 4, 'Varun': 7,
3. Write a Python program to combine two
'Pranav': 3, }
dictionary adding values for common keys.
sorted_items = sorted(asc_dec.items(),
a. d1 = {'a': 100, 'b': 200, 'c':300}
key=lambda item: item[1])
b. d2 = {'a': 300, 'b': 200,’d’:400}
sorted_dict = dict(sorted_items)
dic1 = {'a': 100, 'b': 200, 'c': 300}
print(sorted_dict)
dic2 = {'a': 300, 'b': 200, 'c': 400}
OUTPUT:
combined_dict = {}
{'Pranav': 3, 'Aranav': 4, 'Varun': 7, 'Suyash':
9} for key in set(dic1.keys()).union(dic2.keys()):
==================================== combined_dict[key] = dic1.get(key, 0) +
dic2.get(key, 0)
2. Write a Python script to concatenate
following dictionaries to create a new one. print(combined_dict)
a. Sample Dictionary: OUTPUT:
b. dic1 = {1:10, 2:20} {'c': 700, 'a': 400, 'b': 400}
c. dic2 = {3:30, 4:40} ====================================
d. dic3 = {5:50,6:60} 5. Write a Python program to find the
highest 3 values in a dictionary.
dic1 = {1: 10, 2: 20}
my_dict = {'a': 30, 'b': 30, 'c': 9, 'd': 25, 'e':
dic2 = {3: 30, 4: 40}
15}
dic3 = {5: 50, 6: 60}
sitem = sorted(my_dict.items(), key=lambda
x: x[1], reverse=True)
PRACTICAL NO.9

highest = dict(sitem[:3])

print("Original Dictionary:", my_dict)

print("Highest 3 values:", highest)

OUTPUT:

Original Dictionary: {'a': 30, 'b': 30, 'c': 9, 'd':


25, 'e': 15}

Highest 3 values: {'a': 30, 'b': 30, 'd': 25}

**********************

You might also like