Python filter() function

The filter() function constructs an iterator from those elements of iterable for which the parameter ‘function’ returns a Boolean value true.

Syntax

Parameter

function: This parameter represents a function to be run for each item in the iterable

Iterable:  It represents the iterable to be filtered

Return

This function returns an iterator where the items are filtered through a function to test if the item is accepted or not.

Example 1

Output

 

Example 2

Output

 

Pin It on Pinterest

Share This