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')
1dict = {'an':30, 'example':18}
2#1 Del
3del dict['an']
4
5#2 Pop (returns the value deleted, but can also be used alone)
6#You can optionally set a default return value in case key is not found
7dict.pop('example') #deletes example and returns 18
8dict.pop('test', 'Key not found') #returns 'Key not found'
1squares = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
2
3# remove a particular item, returns its value
4# Output: 16
5print(squares.pop(4))