11 Ways to Work with Lists of Dictionaries in Python

Claudio Sabato
7 min readApr 13

Are you creating a Python program that requires a list of dictionaries and you don’t know how to do it? You will learn how in this tutorial.

A list of dictionaries is a Python list in which every element is a dictionary. Using list methods you can execute operations like creating a brand new list of dictionaries, appending a dictionary to a list, updating a dictionary in a list, or deleting a dictionary from a list. You can also use list comprehensions to search for a dictionary in a list based on the value of a dictionary key.

Let’s learn how to work with this data structure!

How to Create a List of Dictionaries in Python

The first thing we will learn about lists of dictionaries is how to create them.

Imagine you are creating an application in which you have to track multiple users and each user has several properties (e.g. name, surname, and age). You could use a list of dictionaries as a data type to handle this requirement.

The properties related to one user can be represented with the following dictionary:

user1 = {'name': 'John', 'surname': 'Red', 'age': 27}

To track the properties of multiple users you can define a list of dictionaries:

users = [
{'name': 'John', 'surname': 'Red', 'age': 27},
{'name': 'Kate', 'surname': 'Green', 'age': 40},
{'name': 'Jack', 'surname': 'Brown', 'age': 32}
]

Notice that we use the comma to separate items in the list that in this case are dictionaries.

Let’s print the users variable and confirm its type using the type() built-in function:

print(users)

[output]
[{'name': 'John', 'surname': 'Red', 'age': 27}, {'name': 'Kate', 'surname': 'Green', 'age': 40}, {'name': 'Jack', 'surname': 'Brown', 'age': 32}]

print(type(users))

[output]
<class 'list'>

We will also use a for loop to confirm that each element of the list is a dictionary:

for user in users:
print(type(user))

[output]
<class 'dict'>
<class 'dict'>
<class 'dict'>

How to Add a Dictionary to a List of Dictionaries

Claudio Sabato

Claudio Sabato is an IT expert with over 15 years of professional experience in Python/Bash programming, Linux Systems Administration and IT Systems Design.