Functions of filter and map
Let's talk about filter and map functions in Python.
We'll cover the following...
filter
The filter
built-in function will take a function and an iterable
and return an iterator for those elements within the iterable for which
the passed in function returns True
. That statement sounds a bit
confusing to read.
Example of filter()
Let’s look at an example:
Press + to interact
def less_than_ten(x):return x < 10my_list = [1, 2, 3, 10, 11, 12]for item in filter(less_than_ten, my_list):print(item)
Here we create a simple function that tests if the integer we pass ...