Nested Collections
Collections can hold other collections. A list of dictionaries is the usual way to model a table of records. Read deeper values by chaining brackets.
Example
students = [
{"name": "Ada", "scores": [90, 85]},
{"name": "Tunde", "scores": [70, 80]},
]
print(students[0]["name"])
print(students[1]["scores"][0])
for s in students:
print(s["name"], sum(s["scores"]) / len(s["scores"]))Result
Ada 70 Ada 87.5 Tunde 75.0
Exercise
Read the first score of the first student.
print(students[0]["scores"][])
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.