Collections can contain other collections.
Apps often store structured data as lists of dictionaries or dictionaries whose values are lists.
student = {"name": "Ana", "scores": [8, 9]}
print(student["scores"][1])First the key selects the inner list; then index 1 selects its second score.
Try changing one value, then explain which part of the collection changed and why.
Keep this in mind: Read the collection operation before predicting the result.
students = [
{"name": "Ana", "scores": [8, 9]},
{"name": "Marko", "scores": [7, 10]}
]
print(students[0]["name"])
print(students[1]["scores"][0])Run the example, then change one value and observe the result.
users = [{"name": "Ana"}, {"name": "Marko"}]
print(users[1]["name"])Use a numeric index to choose a dictionary from the list, then a key to choose its value.
groups = {"python": ["Ana", "Marko"]}
print(groups["python"][0])Use a key to choose the list, then an index to choose an item inside it.
