Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about Array or List of Dictionaries in Python. so without wasting time lets learn about of this.
Array or List of Dictionaries in Python
- Array or List of Dictionaries in Python
To print Array or List of Dictionaries in Python use this. By using this method you can print array or list of dictionary in python.
lst = [{'aarti':36,'heeya':45}, {'saurabh':56,'sakshi':65}] print(lst[1]) print(lst[1]['sakshi'])
Output :{'saurabh': 56, 'sakshi': 65} 65
- Array or List of Dictionaries in Python
To print Array or List of Dictionaries in Python use this. By using this method you can print array or list of dictionary in python.
lst1 = [{'aarti':36,'heeya':45} for i in range(4)] print(lst1)
Output :[{'aarti': 36, 'heeya': 45}, {'aarti': 36, 'heeya': 45}, {'aarti': 36, 'heeya': 45}, {'aarti': 36, 'heeya': 45}]
- python array of dictionaries
To print Array or List of Dictionaries in Python use this. By using this method you can print array or list of dictionary in python.
lst1 = [{'aarti':36,'heeya':45} for i in range(4)] print(lst1)
Output :[{'aarti': 36, 'heeya': 45}, {'aarti': 36, 'heeya': 45}, {'aarti': 36, 'heeya': 45}, {'aarti': 36, 'heeya': 45}]
Method 1: Array or List of Dictionaries in Python
By using this method you can print array or list of dictionary.
lst = [{'aarti':36,'heeya':45},
{'saurabh':56,'sakshi':65}]
print(lst[1])
print(lst[1]['sakshi'])
Output :
{'saurabh': 56, 'sakshi': 65}
65
Method 2: python array of dictionaries
By using this method you can print array or list of dictionary.
lst1 = [{'aarti':36,'heeya':45} for i in range(4)]
print(lst1)
Output :
[{'aarti': 36, 'heeya': 45}, {'aarti': 36, 'heeya': 45}, {'aarti': 36, 'heeya': 45}, {'aarti': 36, 'heeya': 45}]
Method 3:
By using this method you can print array or list.
lst1 = [dict() for i in range(3)]
print(lst1)
Output :
[{}, {}, {}]
Conclusion
It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?
Also, Read