0% found this document useful (0 votes)
26 views6 pages

Nested Dictionaries in Python Explained

A nested dictionary in Python is a dictionary that contains other dictionaries, allowing for the representation of complex data structures. The document explains how to access, add, update, loop through, and delete items in nested dictionaries using examples. It provides practical code snippets to illustrate these operations on a student data structure.

Uploaded by

narsingojurishi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views6 pages

Nested Dictionaries in Python Explained

A nested dictionary in Python is a dictionary that contains other dictionaries, allowing for the representation of complex data structures. The document explains how to access, add, update, loop through, and delete items in nested dictionaries using examples. It provides practical code snippets to illustrate these operations on a student data structure.

Uploaded by

narsingojurishi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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"]

You might also like