Python 3.14+fnmatchfunction
fnmatch.filterfalse()
filename patterns
The inverse of filter(): a list of the names that do NOT match the pattern (3.14+).
Syntax
fnmatch.filterfalse(names, pat)
Before 3.14 it did not exist, and excluding by pattern meant a loop with not fnmatch(). Like filter(), it returns a list rather than a lazy iterator despite sharing a name with itertools.filterfalse, and case follows the OS rules. Handy for dropping build artefacts: filterfalse(names, '*.pyc').
Examples
import fnmatch
names = ['a.py', 'a.pyc', 'b.py', 'b.pyc']
kept = fnmatch.filterfalse(names, '*.pyc')
print(kept, type(kept).__name__) # → ['a.py', 'b.py'] list
See also
Open in the full glossarydocs.python.orgReport an inaccuracy