Sunday, 27 December 2020

Python: Dictionary in a dictionary

dict_in_dict.py

country_capitals = {"India" : "New Delhi", "Bangladesh" : "Dhaka", "France" : "Paris"}
numbers = {1 : "One", 2: "Two"}

my_dictionary = {"countryCapitals": country_capitals, "numbers" : numbers}

for key in my_dictionary.keys():
	print(f"{key} -> {my_dictionary[key]}")

 

Output

$ python3 dict_in_dict.py 
countryCapitals -> {'India': 'New Delhi', 'Bangladesh': 'Dhaka', 'France': 'Paris'}
numbers -> {1: 'One', 2: 'Two'}

 

 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment