my_dict = {'a': 1, 'b': 2, 'c': 3} del my_dict['b'] print(my_dict)
{'a': 1, 'c': 3}
You can delete an element from a dictionary in Python by using the del statement and specifying the key of the element you want to remove.
The above code will remove the key-value pair where the key is 'b'.
Alternatively, you can also use the pop() method with the key of the element as an argument. For example:
my_dict = {'a': 1, 'b': 2, 'c': 3} my_dict.pop('b')
Learn Flask development and learn to build cool apps with our premium Python course on Udemy.