Let's talk about two other useful functions that Python provides and that are very often use along with lambda functions. First we have the map function, which takes a function and the sequence as arguments, and applies the function to all the elements of the sequence returning an iterable object as the result, the function taken as the first argument may be a previously defined function or a lambda function. So let's try this first using a predefined function that we will create. Let's define a function that takes a parameter and multiplies it by 10. Okay, this is the function now let's create a range object, or one equals arrange of 10. And next let's use the map function to apply the product 10 function to each element in range of 10.
So map, the name of the function product then comma and the name of the range object or one Okay, the result, just as I said is an iterable object. In order to get a list instead of this object, we can simply apply the list function on it. So list. And indeed, this returns a list where each element is the result of multiplying each of the elements in a range of 10 with 10. Let's do the same thing, this time using a lambda function. And now let's apply the list function on this as well.
Notice that the same result is achieved this time using a single line of code. Note that the lambda function body may or may not be enclosed by parentheses. You should better use parentheses though for better readability. Now, the filter function also takes a function and the sequence as arguments. And its role is to extract all the elements in the sequence for which the function returns true. Let's go ahead and use the lambda function and the same range r1.
So filter of lambda a where a is good Throw them five, karma and r1. Let's again apply the list function. So this is pretty intuitive. I think the lambda function returns true if applied on r1. It finds elements greater than five, then the filter function returns an object referencing those elements only. Therefore remember these two functions that Python provides to help you deal more easily with different tasks.
They may come in handy someday.