🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Python Notes
Topic #68

Nested Dictionaries


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 CodingNow 2.0'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 CodingNow 2.0 explains Nested Dictionaries in Python — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Python topic on CodingNow 2.0, 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 CodingNow 2.0'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 CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now