How to Remove Duplicate Elements from Python List?

Elshad Karimov
Oct 27, 2021

Most straightforward approach to removing duplicates in a list is probably using the set() function. Because in Set the values are unique.

# Sample listmy_list = [1,2,3,2,1,2,3,4,5,4,5,3,1]# Create set from listmy_set = set(my_list)# Then override the my_list with new list from Setmy_list = list(my_set)
print(my_list)
# [1, 2, 3, 4, 5]

--

--

Elshad Karimov
Elshad Karimov

Written by Elshad Karimov

Software Engineer, Udemy Instructor and Book Author, Founder at AppMillers

No responses yet