filter()

Filters an iterable by testing each element with a function.

Syntax

python
filter(function, iterable)

Example

python
nums = [1, 2, 3, 4, 5, 6]
evens = list(filter(lambda x: x % 2 == 0, nums))
# [2, 4, 6]