AI engineering glossary · Python core

What is filter?

filter: A built-in function that keeps only the items of an iterable for which a given function returns a true value, returning a lazy iterator. It is an alternative to a comprehension with an if.

Level: intermediateTopic: Python core

filter: an example

list(filter(lambda n: n > 2, [1, 3, 5])) gives [3, 5].

Related terms

More Python core terms

Where you learn it

filter is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.