def _iter_valid_files(directory, white_list_formats, follow_links):
    'Iterates on files with extension in `white_list_formats` contained in `directory`.\n\n    # Arguments\n        directory: Absolute path to the directory\n            containing files to be counted\n        white_list_formats: Set of strings containing allowed extensions for\n            the files to be counted.\n        follow_links: Boolean.\n\n    # Yields\n        Tuple of (root, filename) with extension in `white_list_formats`.\n    '

    def _recursive_list(subpath):
        return sorted(os.walk(subpath, followlinks=follow_links), key=(lambda x: x[0]))
    for (root, _, files) in _recursive_list(directory):
        for fname in sorted(files):
            for extension in white_list_formats:
                if fname.lower().endswith('.tiff'):
                    warnings.warn("Using '.tiff' files with multiple bands will cause distortion. Please verify your output.")
                if fname.lower().endswith(('.' + extension)):
                    (yield (root, fname))
Iterates on files with extension in `white_list_formats` contained in `directory`.

# Arguments
    directory: Absolute path to the directory
        containing files to be counted
    white_list_formats: Set of strings containing allowed extensions for
        the files to be counted.
    follow_links: Boolean.

# Yields
    Tuple of (root, filename) with extension in `white_list_formats`.
def _iter_valid_files(directory, white_list_formats, follow_links):
    'Iterates on files with extension in `white_list_formats` contained in `directory`.\n\n    # Arguments\n        directory: Absolute path to the directory\n            containing files to be counted\n        white_list_formats: Set of strings containing allowed extensions for\n            the files to be counted.\n        follow_links: Boolean.\n\n    # Yields\n        Tuple of (root, filename) with extension in `white_list_formats`.\n    '

    def _recursive_list(subpath):
        return sorted(os.walk(subpath, followlinks=follow_links), key=(lambda x: x[0]))
    for (root, _, files) in _recursive_list(directory):
        for fname in sorted(files):
            for extension in white_list_formats:
                if fname.lower().endswith('.tiff'):
                    warnings.warn("Using '.tiff' files with multiple bands will cause distortion. Please verify your output.")
                if fname.lower().endswith(('.' + extension)):
                    (yield (root, fname))