Create a Unique List in Python

Let’s create a list that will only have unique elements. In other words, we will add value only if there is no same value inside our list.

Inside the code, there is the for loop. This loop iterates through each element of the list_of_elements list and checks whether the value is already inside the unique_list list. If it’s not present, the program adds this element. Otherwise, it returns False and checks the next iteration.

If you run this code, you are going to get the following result:

[5, 2, 4, 3, 1, 6, 10, 7, 8, 9]

As you can see, there are no duplicates – each value is unique.