how to remove items from a dictionary in python code example
Example 1: python remove a key from a dictionary
del dictionary['key']
dictionary = {'a': 3, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
del dictionary['c']
dictionary
--> {'a': 3, 'b': 2, 'd': 4, 'e': 5}
Example 2: python delete value from dictionary
dict = {'an':30, 'example':18}
del dict['an']
dict.pop('example')
dict.pop('test', 'Key not found')
Example 3: remove keys from dict python
'''
Deleting an entry from dictionary using del
'''
if "at" in wordFreqDic:
del wordFreqDic["at"]
print("Updated Dictionary :" , wordFreqDic)