Python Dictionary Methods — Explained
❓ What is a dictionary ❓

Dictionary is an unordered data structure that allows you to store key-value pairs. Here’s an example of a simple Python dictionary:

This dictionary uses strings as keys, but the key can be, in principle, any immutable data type. The value of a particular key can be anything. Here’s another example of a dictionary where keys are numbers and values are strings:

An important clarification: if you try to use a mutable data type as a key (e.x. list), you will get an error:

In fact, the problem is not with mutable data types, but with non-hashable data types, but usually, they are the same thing.

Retrieving data from a dictionary 📖

Square brackets are used to get the value of a particular key [] . Suppose we have a pair in our dictionary 'marathon': 26 :

Again, you will get an error if you try to retrieve a value for a non-existent key. There are methods to avoid such mistakes, which we will talk about now.

Adding and updating keys 🔑

Adding new pairs to the dictionary is quite simple:

Updating existing values is exactly the same:

Deleting keys ❌
['Mikhail Raevskiy']
['Programming', 'Data Science', 'Software Development', 'Python', 'Technology']