Python Tutorials
Basic

Data Structure and Data Types

String

List

Tuple

Set

Dictionary

Functions / Methods

Advance

Exception Handling

Python Nested Dictionary


Nested Dictionary

In Python, a dictionary containing other dictionaries is called the nested dictionary.

Example
company_dictionary = {
    "company_1": {
        "name": "Google", 
        "country": "USA", 
        "start_year": 1995
    }, 
    "company_2": {
        "name": "Microsoft", 
        "country": "USA", 
        "start_year": 1975
    }
}

print(company_dictionary)
{'company_1': {'name': 'Google', 'country': 'USA', 'start_year': 1995}, 'company_2': {'name': 'Microsoft', 'country': 'USA', 'start_year': 1975}}
OR
Example
company_details_1 = {
    "name": "Google", 
    "country": "USA", 
    "start_year": 1995
}, 
company_details_2 = {
    "name": "Microsoft", 
    "country": "USA", 
    "start_year": 1975
}

company_dictionary = {
    "company_1": company_details_1, 
    "company_2": company_details_2
}

print(company_dictionary)
{'company_1': {'name': 'Google', 'country': 'USA', 'start_year': 1995}, 'company_2': {'name': 'Microsoft', 'country': 'USA', 'start_year': 1975}}

In the above example, company_dictionary is our parent dictionary, and company_1 and company_2 are our child dictionaries.