1# Basic syntax:
2del dictionary['key']
3
4# Example usage:
5dictionary = {'a': 3, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
6del dictionary['c'] # Remove the 'c' key:value pair from dictionary
7dictionary
8--> {'a': 3, 'b': 2, 'd': 4, 'e': 5}
1>>> # initialise a dictionary with the keys “city”, “name”, “food”
2>>> person1_information = {'city': 'San Francisco', 'name': 'Sam', "food": "shrimps"}
3
4>>> # delete the key, value pair with the key “food”
5>>> del person1_information["food"]
6
7>>> # print the present personal1_information. Note that the key, value pair “food”: “shrimps” is not there anymore.
8>>> print(person1_information)
9{'city': 'San Francisco', 'name': 'Sam'}
1'''
2Deleting an entry from dictionary using del
3'''
4# If key exist in dictionary then delete it using del.
5if "at" in wordFreqDic:
6 del wordFreqDic["at"]
7
8print("Updated Dictionary :" , wordFreqDic)
9
1dict.pop('key')
2
3#optionally you can give value to return if key doesn't exist (default is None)
4dict.pop('key', 'key not found')