It's mainly for your convenience
Reprint the original link : Python Remove duplicate elements from list
You can also refer to Several ways to delete duplicate elements in the list
list1 = [1, 2, 5, 6, 7, 4, 8, 2, 7, 9, 4, 6, 3]
list2 = list(set(list1))
print(list2)
The output is as follows :
Will change the order of the original list elements .
[1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = [1, 2, 5, 6, 7, 4, 8, 2, 7, 9, 4, 6, 3]
list2 = []
for i in list1:
if i not in list2:
list2.append(i)
print(list2)
The output is as follows :
It will not change the order of the original list elements .
[1, 2, 5, 6, 7, 4, 8, 9, 3]
list1 = [1, 2, 5, 6, 7, 4, 8, 2, 7, 9, 4, 6, 3]
list2 = []
[list2.append(i) for i in list1 if i not in list2] # append Don't forget to add parameters
print(list2)
The output is as follows :
Do not change the order of the original list elements
[1, 2, 5, 6, 7, 4, 8, 9, 3]