A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3schools.com/python/ref_func_filter.asp below:

Website Navigation


Python filter() Function

Python filter() Function

❮ Built-in Functions

Example

Filter the array, and return a new array with only the values equal to or above 18:

ages = [5, 12, 17, 18, 24, 32]

def myFunc(x):

if x < 18:

return False

else:

return True

adults = filter(myFunc, ages)

for x in adults:

print(x)

Try it Yourself » Definition and Usage

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

Syntax

filter(function, iterable)

Parameter Values Parameter Description function A Function to be run for each item in the iterable iterable The iterable to be filtered

❮ Built-in Functions

Track your progress - it's free!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4