Skip to content

Create a list of dictionaries Python | Example code

  • by

Python List can have any Python object. Simple stores the data in the key: value format to Create a list of dictionaries in Python.

Syntax: the dictionary is present as an element in the list. Create a Python list whose each element is nothing but a Python dictionary.

[{key:element1,key:element2,……, 'key':element n}, {....}]

Example create a list of dictionaries Python

Simple example code creates a list of dictionaries for students’ data where id as key and name as value.

data = [{101: 'Any', 102: 'Bob'},
         {103: 'John', 105: 'Tim'}]

print(data)
print(type(data))

Output:

Create a list of dictionaries Python

Do comment if you have any doubts or suggestions on this Python dictionary topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading