AI Features

Think in Tables

Learn to model tabular data with lists of dictionaries.

You’re now comfortable storing things with dictionaries. Let’s now combine dictionaries into a list so that Python can remember a whole group of things, like a list of people, books, or grades.

This structure helps us model real-world tables in code.

List of people as a table

Let’s look at the code below:

Python
people = [
{"name": "Ava", "age": 25},
{"name": "Zane", "age": 30},
{"name": "Maya", "age": 22}
]
for person in people:
print(person["name"], "is", person["age"], "years old.")

That’s our first data table!

Why are there lists of dictionaries?

Each dictionary represents one item, like a row in a table. The list is the collection of all items (rows).
Perfect for things like:

  • Students in a class

  • Products in a store

  • Animals in a shelter

Your turn: Build a library

Python
books = [
{"title": "1984", "author": "George Orwell"},
{"title": "The Hobbit", "author": "J.R.R. Tolkien"}
]
for book in books:
print(book['title'] , " by " , book['author'])

Add more books or change the titles!

Nice work! You just modeled real-world data in Python—that’s a big step forward!