Professional Documents
Culture Documents
In [1]: dict1={}
print(dict1,type(dict1),"Length of dict1 is: ", len(dict1))
101
{'E_ID ': 'IT101', ' E_Name ': 'Priya', ' DPMT ': ' IT ', 'PLACE': ' TCR '}
NESTED DICTIONARY:
In [5]: students={'abc':{'CS':90,'DS':100,'DBMS':89},
'xyz':{'CS':45,'DS':70,'DBMS':77},
'mno':{'CS':99,'DS':86,'DBMS':98},
'pqr':{'CS':97,'DS':70,'DBMS':59},
'dfg':{'CS':69,'DS':65,'DBMS':67},}
for key,val in students.items():
print(key,val)
LOOPING:
In [4]: dict_mul={'E_ID ' : 'IT101', ' E_Name ' : 'Priya', ' DPMT ' : ' IT ', 'PLACE' : ' TCR '}
print("********KEYS**********")
for key in dict_mul:
print(key,end=' ')
print("\n********VALUES********")
for val in dict_mul.values():
print(val,end=' ')
print("\n******DICTIONARY******")
for key,val in dict_mul.items():
print(key,val,"\t",end=' ')
********KEYS**********
********VALUES********
******DICTIONARY******
Enter key : ID
Enter Value: IT
MODIFYING:
{'key1': 'geeks', 'key2': 'for', 'key3': 'geeks', 'key4': 'is', 'key5': 'fabulous'}
{'key1': 'geeks', 'key2': 'for', 'key3': 'geeks', 'key4': 'is', 'key5': 'fabulous', 'newkey
1': 'portal'}
DELETING:
SORTING:
In [8]: # Python program to sort the list
# alphabetically in a dictionary
dict ={
"L1":["Geeks", "for", "Geeks"],
"L2":["A", "computer", "science"],
"L3":["portal", "for", "geeks"],
}
print("\nBefore Sorting: ")
for x in dict.items():
print(x)
print("\nAfter Sorting: ")
for i, j in dict.items():
sorted_dict ={i:sorted(j)}
print(sorted_dict)
Before Sorting:
After Sorting: