Skip to content
dreamcode
dreamcode
Map
Nested data
Lesson 30 of 77
+15 XP on finish
COLLECTIONSChapter 5 · Collections

Nested data

Real data is nested: a list of dictionaries (like rows in a table), or a dictionary whose values are lists. Read it one level at a time: stars[0] is the first dictionary, and stars[0]["name"] is its name. Loop over the outer list, then use keys on each item.

Worked example

How it reads

  • Each index or key goes one level deeper: stars[0]["tags"][1]
  • Loop over the outer list; each star is a whole dictionary
  • in works on the inner list too: "bright" in star["tags"]
Cloud tip: Lost in nested data? Print one level at a time: print(stars[0]), then print(stars[0]["tags"]).
main.py
PYTHON
real Python, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Print the second pilot's name (Luka), then the total number of crew members (3).

Press Run to check your work.