def uniq_g(lst, key=lambda value: value):
    """
    Get unique elements of an iterable preserving its order and optionally
    determining uniqueness by hash of a key.
    """
    known = set()
    for value in lst:
        value_key = key(value)
        if value_key not in known:
            yield value
            known.add(value_key)
