human
Complete this python program:
def _list_valid_filenames_in_directory(directory, white_list_formats, class_indices, follow_links):
assistant
#Here is the Python program you requested.

    """List paths of files in `subdir` relative from `directory` whose extensions are in `white_list_formats`.
    # Arguments
    directory: absolute path to a directory containing the files to list.
    The directory name is used as class label and must be a key of `class_indices`.
    white_list_formats: set of strings containing allowed extensions for
    the files to be counted.
    class_indices: dictionary mapping a class name to its index.
    # Returns
    classes: a list of class indices
    filenames: the path of valid files in `directory`, relative from
    `directory`\s parent (e.g., if `directory` is "dataset/class1",
    the filenames will be ["class1/file1.jpg", "class1/file2.jpg", ...]).
    """
    def _recursive_list(subpath):
        return sorted(os.walk(subpath, followlinks=follow_links), key=(lambda tpl: tpl[0]))
    classes = []
    filenames = []
    subdir = os.path.basename(directory)
    basedir = os.path.dirname(directory)
    for (root, _, files) in _recursive_list(directory):
        for fname in files:
            is_valid = False
            for extension in white_list_formats:
                if fname.lower().endswith(('.' + extension)):
                    is_valid = True
                    break
            if is_valid:
                classes.append(class_indices[subdir])
                absolute_path = os.path.join(root, fname)
                filenames.append(os.path.relpath(absolute_path, basedir))
    return (classes, filenames)