Python for Data Analytics • Lesson 9

Dictionaries

Learn how Python dictionaries store information using key-value pairs and how to access, add, update, remove and process data.

Your progress0%

0 of 8 concepts completed

Complete the activity and related MCQ to unlock the next concept.

Concept 1KEY-VALUE

What Is a Dictionary?

A dictionary stores data as key-value pairs inside curly braces { }. Instead of numeric positions, you look values up by their named keys.

Learn by Seeing

Keys map to values

student = {
    "name": "Aman",
    "age": 21,
    "course": "Python"
}

Each key on the left identifies the value on the right.

A dictionary maps each key to its value. Click any pair:

selected pair

key: "name" → value: "Aman"

The key on the left names the value on the right.

Interactive Activity

In the pair "name": "Aman", what is the key?

Hint: The key is on the left of the colon.

Python Analyst Mindset

Name your fields, not your positions

Positions are easy to mix up; names are not. Dictionaries let you write product["price"] instead of record[2] — code that reads like the record itself and survives when a column is inserted.

01

Create

Wrap key-value pairs in { }.

02

Look up

dict[key] or dict.get(key).

03

Grow

Assign a new key or update an existing one.

04

Inspect

keys(), values(), items().

Frequently Asked Questions

Dictionaries — FAQs

What is the difference between dict[key] and get()?

dict[key] raises a KeyError for missing keys. get() returns None (or a default) instead — safer for unknown data.

Can a dictionary hold different value types?

Yes. Values can be any type, and you can even nest other dictionaries as values.

Are keys ordered in a dictionary?

Yes, since Python 3.7 dictionaries preserve insertion order, though you should not rely on that for logic.

Can a key appear twice?

No. Assigning the same key again overwrites the value — the dictionary has only one entry per key.

Lesson Summary

What you learned

Key-value pairs

Dictionaries map named keys to values.

Access & update

dict[key] reads or replaces the value.

Add & remove

Assign a new key to add; pop(key) to remove.

get()

Safely reads a value with an optional default.

keys() / values() / items()

Explore the dictionary from three angles.

in and nested dictionaries

Test for keys and store structured records.