student = {
"name": "Alice",
"age": 21,
"major": "Computer Science"
}
print(student["name"])
print(student["major"])Alice
Computer Science
In Python, a dictionary represents one item (e.g., one student). To store multiple such items, we use a list of dictionaries.
One Dictionary for One Student
Alice
Computer Science
List of Dictionaries for Multiple Students
Math
Looping Through a List of Dictionaries
Alice is studying CS
Bob is studying Math
Cara is studying Biology
Exercise
students list.Alice is 21 years old.
Bob is 22 years old.
Cara is 20 years old.
Kate is 21 years old.
[{'name': 'Alice', 'age': 21, 'major': 'CS'}, {'name': 'Bob', 'age': 22, 'major': 'Political Science'}, {'name': 'Cara', 'age': 20, 'major': 'Biology'}, {'name': 'Kate', 'age': 21, 'major': 'Computer Science'}]