0% found this document useful (0 votes)
21 views3 pages

Python 09

The document contains practical exercises involving Python dictionaries and lists. It demonstrates operations such as sorting dictionaries, updating them, merging values, extracting unique values from a list of dictionaries, and finding the largest values in a dictionary. Each exercise includes code snippets and expected outputs.

Uploaded by

yashmahajan4433
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Python 09

The document contains practical exercises involving Python dictionaries and lists. It demonstrates operations such as sorting dictionaries, updating them, merging values, extracting unique values from a list of dictionaries, and finding the largest values in a dictionary. Each exercise includes code snippets and expected outputs.

Uploaded by

yashmahajan4433
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

practical 9

1.
d={1:"one",5:"five",2:"two"}
print(d)
print(sorted(d))
output:

2.
dict1={1:10,2:20}
dict2={3:30,4:40}
dict3={5:50,6:60}
dict4={0:0}

[Link](dict1)
[Link](dict2)
[Link](dict3)

print("DICT=",dict4)
output:
3.
dict1={"a":100,"b":200,"c":300}
dict2={"a":300,"b":200,"d":400}
dict3={}
print("dict1=",dict1)
print("dict2=",dict2)

[Link](dict1)
[Link](dict2)

for key in dict1:


if key in dict2:
dict3[key]=dict2[key]+dict1[key]
print("new dict==",dict3)
output:

4.
L=[{"V":"s001"},{"V":"s002I","VI":"s001"},{"VI":"s005"},{"VII":"s005"},{"V":"s009"},
{"VIII":"s007"}]
print("original list==",L)

uniqueval=set(val for dic in L for val in [Link]())


print("unique values =",uniqueval)
5.
from heapq import nlargest
dict={1:234,2:100,3:255,4:243,5:895}
print("original dict=",dict)

largestno=nlargest(3,dict,key=[Link])
print("Largest values==",largestno)
output:

You might also like