def unique(seq, key=None, reverse=False):
    'Given a sequence return a list only with unique elements while maintaining order\n\n    This is the fastest solution.  See\n    https://www.peterbe.com/plog/uniqifiers-benchmark\n    and\n    http://stackoverflow.com/a/480227/1265472\n    for more information.\n    Enhancement -- added ability to compare for uniqueness using a key function\n\n    Parameters\n    ----------\n    seq:\n      Sequence to analyze\n    key: callable, optional\n      Function to call on each element so we could decide not on a full\n      element, but on its member etc\n    reverse: bool, optional\n      If True, uniqueness checked in the reverse order, so that the later ones\n      will take the order\n    '
    seen = set()
    seen_add = seen.add
    trans = (reversed if reverse else (lambda x: x))
    if (not key):
        out = [x for x in trans(seq) if (not ((x in seen) or seen_add(x)))]
    else:
        out = [x for x in trans(seq) if (not ((key(x) in seen) or seen_add(key(x))))]
    return (out[::(- 1)] if reverse else out)
Given a sequence return a list only with unique elements while maintaining order

This is the fastest solution.  See
https://www.peterbe.com/plog/uniqifiers-benchmark
and
http://stackoverflow.com/a/480227/1265472
for more information.
Enhancement -- added ability to compare for uniqueness using a key function

Parameters
----------
seq:
  Sequence to analyze
key: callable, optional
  Function to call on each element so we could decide not on a full
  element, but on its member etc
reverse: bool, optional
  If True, uniqueness checked in the reverse order, so that the later ones
  will take the order
def unique(seq, key=None, reverse=False):
    'Given a sequence return a list only with unique elements while maintaining order\n\n    This is the fastest solution.  See\n    https://www.peterbe.com/plog/uniqifiers-benchmark\n    and\n    http://stackoverflow.com/a/480227/1265472\n    for more information.\n    Enhancement -- added ability to compare for uniqueness using a key function\n\n    Parameters\n    ----------\n    seq:\n      Sequence to analyze\n    key: callable, optional\n      Function to call on each element so we could decide not on a full\n      element, but on its member etc\n    reverse: bool, optional\n      If True, uniqueness checked in the reverse order, so that the later ones\n      will take the order\n    '
    seen = set()
    seen_add = seen.add
    trans = (reversed if reverse else (lambda x: x))
    if (not key):
        out = [x for x in trans(seq) if (not ((x in seen) or seen_add(x)))]
    else:
        out = [x for x in trans(seq) if (not ((key(x) in seen) or seen_add(key(x))))]
    return (out[::(- 1)] if reverse else out)