Back to Python Notes
Topic #68

Nested Dictionaries

Nested dictionaries store dictionaries inside dictionaries, modelling rich structures like users with addresses. JSON data often arrives this way.


Nested Dictionaries

A dictionary can contain dictionaries, this is called nested dictionaries.

Example

myfamily = {
  "child1" : {
    "name" : "Emil",
    "year" : 2004
  },
  "child2" : {

"name" : "Tobias",
    "year" : 2007
  },

"child3" : {
    "name" : "Linus",
    "year" : 2011
  }
}

Or, if you want to add three dictionaries into a new dictionary:

Example

child1 = {
  "name" : "Emil",
  "year" : 2004
}
child2 = {

"name" : "Tobias",
  "year" : 2007
}
child3 = {
  "name" : "Linus",

"year" : 2011
}

myfamily = {
  "child1" : child1,

"child2" : child2,
  "child3" : child3
}

Access Items in Nested Dictionaries

To access items from a nested dictionary, you use the name of the dictionaries, starting with the outer dictionary:

Example

print(myfamily["child2"]["name"])

Loop Through Nested Dictionaries

You can loop through a dictionary by using the items() method like this:

Example

for x, obj in myfamily.items():
  print(x)

  for y in obj:
    print(y + ':', obj[y])

Want to go beyond the notes?

Join Coding Now Tech Institute's Python course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Nested Dictionaries – FAQs

Quick answers about learning Nested Dictionaries in Python.

This free note from Coding Now Tech Institute explains Nested Dictionaries in Python — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Python topic on Coding Now Tech Institute, including Nested Dictionaries, is 100% free with no signup required.
With focused practice, most students grasp Nested Dictionaries in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now