How to remove duplicates from a list in python?
![](https://pythonpoint.net/wp-content/uploads/2020/12/Orange-Greyscale-Photo-Gaming-YouTube-Channel-Art-3-1024x576.jpg)
A list is a data structure, or it can be considered that can be used to store multiple data at once. The list will be ordered and there will be a definite count of it.
Here we;ll see how to remove duplicate elements from a list in python. There are many methods for this.
e.g., (by using loops)
list1 = [1, 2, 3, 4, 3, 2] t = [] for x in list1: if x not in t: t.append(x) list1 = t print(t)
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-1080-1024x300.png)
e.g., (set method)
l = [1, 2, 3, 4, 3, 2, 4, 3, 2] l1 = list(set(l)) print(l1)
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-1082-1024x250.png)
e.g., (dictionary method)
l = [1, 3, 2, 1, 4, 2, 4, 3] l1 = list(dict.fromkeys(l)) print(l1)
![](https://pythonpoint.net/wp-content/uploads/2020/12/Screenshot-1084-1024x209.png)
In this way we can remove duplicates from a list in python.
Subscribe
Login
Please login to comment
0 Discussion