Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dictionary basics
7. Deleting dictionary elements
Dictionaries in loops and conditional statements
Dictionaries in functions
Summary

Instruction

Good job! To delete a dictionary entry, you can use the del operator, just like with lists:

phonebook = {'Mary': '8349374', 'Anne': '7439834', 'John': '3472983'}
del phonebook['Mary'] # Mary no longer with us

In the case of lists, the del operator was dangerous, as it shifted multiple indices in the list to clean up empty spaces in the list.

Dictionaries, on the other hand, use keys that do not follow any specific order. This means that no changes are made to other dictionary elements when we delete one of them.

Exercise

Delete the dictionary item from 2001 that you added in the previous exercise.

Stuck? Here's a hint!

Use the del operator.