{"id":24815,"date":"2021-11-02T09:48:05","date_gmt":"2021-11-02T04:18:05","guid":{"rendered":"https:\/\/python-programs.com\/?p=24815"},"modified":"2021-11-05T20:37:04","modified_gmt":"2021-11-05T15:07:04","slug":"python-filter-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-filter-function-with-examples\/","title":{"rendered":"Python filter() Function with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python enumerate() Function with Examples<\/a>
\nfilter() Function in Python:<\/strong><\/p>\n

The filter() function returns an iterator in which the items are filtered through a function to determine whether or not the item is accepted.<\/p>\n

Syntax:<\/strong><\/p>\n

filter(function, iterable)<\/pre>\n

Parameter Values:<\/strong><\/p>\n

function:<\/strong> It is a function that will be executed for each item in the iterable.<\/p>\n

iterable:<\/strong> The iterable that will be filtered.<\/p>\n

Return Value:<\/strong><\/p>\n

The iterator is returned by the filter() function.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [3, 10, 12, 13, 20, 7, 1, 16]<\/pre>\n

Output:<\/strong><\/p>\n

The Even numbers in a given list :\r\n10\r\n12\r\n20\r\n16<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [4, 6, 7, 9, 10, 12, 11]<\/pre>\n

Output:<\/strong><\/p>\n

The Even numbers in a given list :\r\n4\r\n6\r\n10\r\n12<\/pre>\n

filter() Function with Examples in Python<\/h2>\n