On this page
fnmatch.filter
Up: fnmatch | Next: fnmatch.filterfalse
Rel: fnmatch.filterfalse, fnmatch.fnmatch, fnmatch.fnmatchcase, fnmatch.translate
Ref: docs.python.org — fnmatch.filter
Tags: #public #python3 #stdlib #fnmatch
Import
import fnmatch
from fnmatch import filter
Signature & Overview
fnmatch.filter(names, pat)
Construct a list from those elements of the iterable NAMES that match PAT.
Usage
import fnmatch
assert fnmatch.filter(["a.py", "b.txt", "c.py"], "*.py") == ["a.py", "c.py"]
Gotchas
- Faster than
[n for n in names if fnmatch(n, pat)]: Compiles the regex once for the whole list.
REPL Inspect
from fnmatch import filter
help(filter)
Linked from
Related notes
- tuts/python3/stdlib_module/fnmatch/filterfalse Linked here; links to this page; shared tags: #fnmatch, #stdlib
- tuts/python3/stdlib_module/fnmatch/fnmatch Linked here; links to this page; shared tags: #fnmatch, #stdlib
- tuts/python3/stdlib_module/fnmatch/fnmatchcase Linked here; links to this page; shared tags: #fnmatch, #stdlib
- tuts/python3/stdlib_module/fnmatch/translate Linked here; links to this page; shared tags: #fnmatch, #stdlib
- tuts/python3/stdlib_module/fnmatch links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib