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

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


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

Browse More Popular Posts

Leave a Comment