Sunday 27 December 2020

Python: List of dictionaries

In this post, I am going to explain how to create list of dictionaries.

 

list_of_dictionary.py

dict1 = {"a" : "A", "b" : "B"}
dict2 = {1 : "One", 2 : "Two"}
country_capitals = {"India" : "New Delhi", "Bangladesh" : "Dhaka", "France" : "Paris"}

list = [dict1, dict2, country_capitals]

for item in list:
	print(f"{item}")

Output

$ python3 list_of_dictionary.py {'a': 'A', 'b': 'B'} {1: 'One', 2: 'Two'} {'India': 'New Delhi', 'Bangladesh': 'Dhaka', 'France': 'Paris'}

 

 

 


 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment