(Last Updated On: 24/04/2023)
Python Program to Remove Duplicate Elements From a List Using in, not in Operators
# Remove Duplicate Element From a List Using in, not in operators in Python
# initializing list
test_list = [1, 2, 9, 5, 6, 3, 5, 6, 1]
print("The original list is : " + str(test_list))
res = []
for i in test_list:
if i not in res:
res.append(i)
# printing list after removal
print("The list after removing duplicates : " + str(res))
Ouput:
The original list is : [1, 2, 9, 5, 6, 3, 5, 6, 1]
The list after removing duplicates : [1, 2, 9, 5, 6, 3]