Categories
Python Answers

How to remove duplicate dict in list in Python?

Spread the love

Sometimes, we want to remove duplicate dict in list in Python.

In this article, we’ll look at how to remove duplicate dict in list in Python.

How to remove duplicate dict in list in Python?

To remove duplicate dict in list in Python, we use the iteration-utilities package.

To install it, we run

pip install iteration-utilities

Then we write

from iteration_utilities import unique_everseen

l = [{'a': 123}, {'b': 123}, {'a': 123}]
no_dups = list(unique_everseen(l))

to call unique_everseen to return an iterator with the duplicate dicts removed.

And then we convert that to a list with list.

Conclusion

To remove duplicate dict in list in Python, we use the iteration-utilities package.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *