On this page
itertools.filterfalse
Prev: itertools.dropwhile | Up: itertools | Next: itertools.groupby
Rel: itertools.accumulate, itertools.batched, itertools.chain, itertools.combinations
Ref: docs.python.org — itertools.filterfalse
Tags: #public #python3 #stdlib #itertools
Import
import itertools
from itertools import filterfalse
Signature & Overview
itertools.filterfalse(function, iterable, /)
Return those items of iterable for which function(item) is false.
Usage
from itertools import filterfalse
# Opposite of built-in filter(): keeps items where predicate is falsy
assert list(filterfalse(lambda x: x % 2 == 0, range(6))) == [1, 3, 5]
assert list(filterfalse(None, [0, 1, "", "ok", None])) == [0, "", None]
Gotchas
predicate=Nonekeeps falsy items: PassingNonereturns items wherebool(item)isFalse(mirroringfilter(None, ...)which keeps truthy items).- Lazy iterator: Consumed once; wrap in
list()ortuple()if you need multiple passes.
REPL Inspect
from itertools import filterfalse
help(filterfalse)
Linked from
Related notes
- tuts/python3/stdlib_module/itertools/dropwhile Linked here; links to this page; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/groupby Linked here; links to this page; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/itertools/accumulate Linked here; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/batched Linked here; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/chain Linked here; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/combinations Linked here; shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/combinations_with_replacement shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/compress shared tags: #itertools, #stdlib
- tuts/python3/stdlib_module/itertools/count shared tags: #itertools, #stdlib