def unique(iterable, key=None):
seen = set()<EOL>seen_add = seen.add<EOL>if key is None:<EOL><INDENT>for element in filterfalse(seen.__contains__, iterable):<EOL><INDENT>seen_add(element)<EOL>yield element<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for element in iterable:<EOL><INDENT>k = key(element)<EOL>if k not in seen:<EOL><INDENT>seen_add(k)<EOL>yield element<EOL><DEDENT><DEDENT><DEDENT>
Yield unique elements, preserving order.