Suppose we have a list
dub_list = [1, 5, 3, 6, 3, 5, 6, 1]
there are many ways to remove duplicate elements from list using set or creating empty list and adding unique elements. However, I wanted to do this work using list comprehension and enumerate function. I found the below solution from a website.
unique_list = [i for n, i in enumerate(dub_list) if i not in dub_list[:n]]
print("The list after removing duplicates : " + str(unique_list))
I couldn't understand the
if i not in dub_list[:n]
I will appreciate if you could put light on this, thank you