turned on laptop computer
Photo by Joshua Aragon on Unsplash

When you are about to use dictionaries, you may have cases when you try to access elements using keys that are not part of the dictionary.

Let us see the following example:

Since the key “age” is not in there, an error will be thrown.

Here it’s the error thrown:

KeyError: 'age'

We can avoid such errors using defaultdict():


This is pretty much it.