Source Code:
(back to article)
original_list = [1, 2, 3, 4, 2, 5, 3, 6] # Use list comprehension to add items to a new list if they haven't been added yet no_duplicates_list = [] for item in original_list: if item not in no_duplicates_list: no_duplicates_list.append(item) print(no_duplicates_list) # Output: [1, 2, 3, 4, 5, 6]
Result:
Report an issue