Search⌘ K
AI Features

Filter

Explore the filter function to selectively remove elements from iterables by applying a testing function. Learn how to use filter with lambda expressions and built-in functions to efficiently process data, returning an iterator with only items that meet specified criteria.

We'll cover the following...

Filtering iterables

The filter function can be used to remove items from an iterable based on a testing function. It returns an iterator to access the result. Here is an example:

Python 3.8
a = [3, 2, 1, 6, 7, 0]
f = filter(lambda x: x > 2, a)
print(list(f))
...