MemotivaComprehensions and functional tools

What does the filter function do?

Comprehensions and functional tools

Audio flashcard · 0:12

Nortren·

What does the filter function do?

0:12

Filter takes a predicate function and an iterable and returns an iterator over elements for which the predicate returns true. Like map, filter is lazy in Python 3. Comprehensions with an if clause are generally preferred for readability.
docs.python.org