In Python, a dictionary containing other dictionaries is called the nested dictionary.
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}}
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.