How to delete duplicated elements from a list in Python

This is a simple way to delete duplicated elements from a list in Python when the order is not important.

>>> l = [1, 2, 2, 3, 4, 1, 3, 5, 6]
>>> l
[1, 2, 2, 3, 4, 1, 3, 5, 6]
>>> l = list(set(l))
>>> l
[1, 2, 3, 4, 5, 6]

In this case, we’re converting our list to a set data structure and take advantage of its “non duplicate elements” property. Then, we convert that object into a list again in order to have the initial data structure but with unique items in it.

Sources:
docs.python.org | Data Structures (Sets)