def ordered_deduplicate(sequence):
    """
    Returns the sequence as a tuple with the duplicates removed,
    preserving input order.  Any duplicates following the first
    occurrence are removed.

    >>> ordered_deduplicate([1, 2, 3, 1, 32, 1, 2])
    (1, 2, 3, 32)

    Based on recipe from this StackOverflow post:
    http://stackoverflow.com/a/480227
    """

    seen = set()
    # Micro optimization: each call to seen_add saves an extra attribute
    # lookup in most iterations of the loop.
    seen_add = seen.add

    return tuple(x for x in sequence if not (x in seen or seen_add(x)))