List Comprehension with if statement and append – Phyton [closed]

I would suggest to use a set. This contains only unique values:

unique=list(set(letters))
print(unique)

If you really would like to use a comprehension you can do this:

s = set()
[i for i in letters if not (i in s or s.add(i))]

This works, because s.add() returns None

Leave a Comment