def deduplicate_list(sequence, rtuple=False):
    """
    Deduplicates a list while preserving order.

    Code based in this Stack Overflow discussion (https://stackoverflow.com/a/480227).

    :param sequence: A sequence of items (list, tuple, or set).
    :type sequence: list || tuple || set

    :param rtuple: Specifies if the function should return it as a tuple instead.
    :type rtuple: bool

    :return: A list (or a tuple, if specified) of the deduplicated sequence.
    :rtype: list || tuple
    """
    seen = set()
    seen_add = seen.add

    if rtuple is True:
        return (item for item in sequence if not (item in seen or seen_add(item)))
    else:
        return [item for item in sequence if not (item in seen or seen_add(item))]