def previously_valid_data(data: list, invalid_data: set):
    """
    Return a list of valid data from a input list. When an element is in the
    invalid data set, is must be replaced with the previous valid data.

    >>> previously_valid_data(['0', '2', None, '1', None, '0', None, '2'], {None})
    ['0', '2', '2', '1', '1', '0', '0', '2']
    >>> previously_valid_data(['0', '2', 'None', '1', None, '0', None, '2'], {None, 'None'})
    ['0', '2', '2', '1', '1', '0', '0', '2']
    """
    last_valid_data = None
    result = list()
    for elem in data:
        if elem not in invalid_data:
            last_valid_data = elem
        result.append(last_valid_data)
    return result