Nested Dictionaries in
Python
UNDERSTANDING MULTI-LEVEL DICTIONARIES
PRESENTED BY: [Link]
What is a Nested Dictionary?
A dictionary inside another dictionary
Used to represent complex data structures
Example:
students = {
"A1": {"name": "Alice", "grade": "A"},
"B2": {"name": "Bob", "grade": "B"}
}
Accessing Data in Nested Dictionaries
Access outer and inner keys:
students["A1"]["name"] # Output: Alice
Adding and Updating Data
Add new: students["C3"] = {"name": "Charlie", "grade": "A"}
Update: students["A1"]["grade"] = "A+"
Looping Through Nested Dictionaries
for student_id, info in [Link]():
print(f"ID: {student_id}")
for key, value in [Link]():
print(f" {key}: {value}")
Output:
ID: A1
name: Alice
grade: A
ID: B2
name: Bob
grade: B
Deleting Items
Delete entry: del students["B2"]
Delete inner key: del students["A1"]["grade"]