WAP to create a dictionary and delete the last entered items in the dictionary
Answers
Answered by
0
Answer:
# Python code to demonstrate
# removal of dict. pair
# using del
# Initializing dictionary
test_dict = {"Arushi" : 22, "Anuradha" : 21, "Mani" : 21, "Haritha" : 21}
# Printing dictionary before removal
print ("The dictionary before performing remove is : " + str(test_dict))
# Using del to remove a dict
# removes Mani
del test_dict['Mani']
# Printing dictionary after removal
print ("The dictionary after remove is : " + str(test_dict))
# Using del to remove a dict
# raises exception
del test_dict['Manjeet']
Similar questions
Math,
1 month ago
English,
1 month ago
Social Sciences,
3 months ago
Biology,
3 months ago
CBSE BOARD X,
9 months ago
Math,
9 months ago