def uniq_p(seq, pred):
    """Returns a copy of `seq` where duplicates with regard to `pred` are
       eliminated while preserving the order of the remaining elements.

       >>> list (range (1, 60, 5))
       [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56]
       >>> list (uniq_p (range (1, 60, 5), lambda x : x%6))
       [1, 6, 11, 16, 21, 26]
    """
    seen = set()
    for e in seq:
        p = pred(e)
        if p not in seen:
            seen.add(p)
            yield e
