def exclude_ext(ext):

    def compare(fn):
        return os.path.splitext(fn)[1] != ext
return compare
files = list(filter(exclude_ext('.dat'), files))
How to filter files (with known type) from os.walk?