How To: Dictionaries


Removing from a dictionary

Removing items from a dictionary is similar to removing from a list. The major difference when dealing with dictionaries is that we've got to delete items by their keys.

For example:

We can continue deleting until the dictionary is empty:

Empty dictionaries act like other dictionaries, and we can start filling them up again:

Deleting keys that don't exist

If we try to delete something from that doesn't exist from the dictionary, we'll get a KeyError:

Challenge

Delete the keys from the breads dictionary in the console one by one: