All posts
postMay 14, 2026

Python dictionaries — key/value lookups

#python#dict#basics
python
user = {
    "id": 42,
    "email": "alice@x.com",
    "country": "MX"
}

print(user["email"])           # direct access
print(user.get("phone", "n/a"))# safe access with default

user["last_login"] = "2026-05-14"# add a key

A dictionary maps keys to values. You access values by key, not by position. Lookups are constant time, which is why dicts are everywhere in data work.

In Data Engineering you use dicts to represent records (one row from a database), to count occurrences (frequency tables), and to map ids to names (lookup tables). Mastering dict.get() with a default value avoids dozens of KeyError exceptions.