seen = set()
for x in foo:
if x in seen:
continue
seen.add(x)
# do something
See the documentation for more information set.
In addition, the examples at the bottom of the itertools document contain a generator unique_everseenthat can be used as follows:
for x in unique_everseen(foo):
source
share