Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

Mini Project: Gradebook

18 min 45 XP
Study loop Read Predict Run Tweak Prove Review
Lesson 6 of 6 · View course roadmap
Step 1

Learn the idea

Real-world data nests: lists of dicts, dicts of lists. A JSON API response is exactly this shape. Let's build a gradebook — a list where each student is a dict:

students = [{"name": "Ada", "grades": [90, 95]}, ...]

Patterns you'll use constantly:

  • Loop the outer list, reach into each dict: for s in students: print(s["name"])
  • Compute per-item stats: sum(s["grades"]) / len(s["grades"])
  • Find the best item by tracking a "best so far" while looping

Where you'll use this

This gradebook shape — a list of dicts — is byte-for-byte what you get from requests.get(...).json(), a CSV DictReader, or a database ORM. Master the drill-down and every API is readable.

Common mistakes

  • Guessing the structure instead of checking: print one element (print(data[0])) before writing access code.
  • Deep chains with no safety: d["a"]["b"]["c"] crashes on the first missing level — use .get() with defaults for optional branches.
  • Tracking 'best so far' but initialising best_avg to 0 — fails when all averages are negative. Initialise to the first element or -infinity.

Pro tip

max(students, key=lambda s: sum(s['grades'])/len(s['grades'])) finds the top student in one line — the key= pattern replaces the whole tracking loop.

Step 2

Try it yourself

Blank · autosaved

The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.

PYexample.py
+ Enter to run
Output appears here…
Step 3

Pass the challenge +45 XP

Blank · autosaved

Using the starter data, print each student's name and average (1 decimal, format Name: avg), then print the name of the student with the highest average.

Target output
Maya: 90.0
Leo: 94.3
Zoe: 75.0
Leo
PYchallenge.py
Run your code to check it…
Step 4

Check your understanding

1. For data = [{"a": [1, 2]}], how do you reach the 2?
Last step

Your notes (saved on this device)

Tip: use and to move between lessons, K to search everything.

Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path