Recently in our Kodik's Telegram community we had an interesting discussion about dictionaries in Python. The guys shared their experiences, told how they use them in real projects, and discussed useful techniques. As a result, we decided to put all these thoughts into an article — so that everyone has a handy "cheat sheet" on dictionaries.
Dictionaries are one of the most convenient and fastest ways to store and process data in Python. If lists are just a set of elements with indexes, then dictionaries allow you to store data in the format key-value. It's like a mini database right in your program. 🚀


What is a dictionary?
A dictionary in Python is a data structure where each element is stored as a pair: ключ: значение. Keys are always unique, and values can be repeated. For example:
person = {
"name": "Ivan",
"age": 25,
"city": "Moscow"
}Now you can quickly get any value by specifying its key: print(person["name"]) # Ivan.
Advantages of dictionaries
⚡ Instant access — searching by key is faster than iterating through list items.
📝 Flexibility — you can store data of different types (strings, numbers, lists and even other dictionaries).
🔑 Readability — the code becomes clearer when the values are signed with keys.
How to work with dictionaries?
You can create a dictionary in different ways:
# 1. Through curly braces
my_dict = {"a": 1, "b": 2}
# 2. Using the dict() function
user = dict(name="Anya", age=30)Adding and changing elements:
user["age"] = 31
user["country"] = "Russia"Removal:
del user["age"]Dictionary methods
Dictionaries have convenient methods for working with data:
.keys()— returns a list of all keys..values()— a list of all values..items()— key-value pairs as tuples..get(key, default)— safely gets the value by key.
print(user.get("name", "Unknown"))Dictionaries and speed
Python uses hash tables to implement dictionaries. This makes accessing values by keys very fast, even if the dictionary contains thousands of elements. That's why dictionaries are so popular for storing and searching data.
Where are dictionaries used?
Dictionaries are used everywhere: from setting up configurations to storing user data. For example, when working with API, JSON or when writing games, dictionaries help to organize information.
In Codice we have created convenient interactive tasks so that you can master dictionaries and other data structures in Python. In the application you will find courses in Python, HTML, CSS and JavaScript, as well as projects for training skills.
Join our Telegram community Codica, where we share life hacks and motivation for developers. 😊
Conclusion
Dictionaries are a powerful tool in Python that allows you to quickly access data and make the code structured. By mastering them, you will simplify your life when working with data of any level of complexity.
