Level 1
0 / 100 XP

Section 5 overview

Lists are great for ordered sequences, but sometimes you need to look something up by name instead of by position. That is what dictionaries are for.

A dictionary (or dict) stores data as key–value pairs. You give it a key, it hands back the value — fast and readable.

What you'll learn

  • Create dictionaries and read values by key
  • Add and update keys
  • Loop over keys, values, and key–value pairs
Python
settings = {"theme": "dark", "volume": 7} print(settings["theme"]) # dark print(settings["volume"]) # 7

Reach for a dict whenever your data has natural labels: settings, user profiles, inventories, counts, or any "name → value" mapping.

Key takeaways

  • A dict stores key–value pairs and looks values up by key.
  • Use a dict when names/labels matter more than order.
  • This section covers creating, accessing, updating, and looping over dicts.