Right now, we would talk about the lamda functions and how we can use them along with MAP Reduce and
fatal.
So first of all, let us discuss what lambda functions actually are.
Lambda functions are one of the python's most useful tools and these are really very difficult and confusing
for the beginners.
So it is very important to pay attention and understand this concept, because once you understand this,
it will be very helpful.
So no function is used to create anonymous functions, so we have been using the def keyboard to create
different functions, I would create a function system and this would basically help me to add to numbers.
So let's say I have no equal maybe.
And I would simply say.
The tone and I would say A plus B, so this function would allow me to read on the some of these two
values so I can any time you sums and give the two there, one or two, and it will simply give me the
result of this thing.
Now it is very easy to use this and it might be a little of you can say find the woman to write this
function and maybe I might use this several number of times.
But there could be a situation when I don't really want to you several functions.
I do want to keep the method aside.
I do want to keep the functionality aside, but I don't really want to reuse this thing again and again.
So what I can do is I can quickly create a small function, which I can use at that time and then completely
forget about.
So that is what lamda function allows me to.
So Lamda is a single expression and it is not a block statement.
So usually when we have the lambda functions or let's say when we have any of the functions.
Let us say I am creating this function sum's, so I am writing these three lines of code.
But in case of a lambda expression it I don't need to write these so many lines of code.
I just need to write a small expression here.
OK, so let us see how we can construct this lambda expression and how we can use this.
OK, so let us see.
I want to create.
Alamdar function, so what I can simply do is I can send these right lamda.
And with Lamda, I want to read the argument, which I want to give, so let us say I want to have equal
maybe these are the two arguments which I wanted to be.
And what I want to give out of what I want to now is what I write next up of this.
So I give all.
And after this I simply say E-Plus.
So I just want to read on E-Plus V and A and B is what I'm speaking from.
So this is a very small lambi expression which I can use any number of times.
OK, now this lambda expression V will not be using like this.
OK, we will not be giving any lame name to it.
So what I can do is I can see something like.
See love.
And I can create this kind of thing, so whenever I do something Laci, I do and I give simplicity to
grandma if I do it so it will give the desired back to me.
But this is what I actually don't want to do.
I don't want to give anything to it.
This is the main concept of lamda function that I don't want to create a mean function.
If I wanted to create a new function, I would have used this only.
OK, so for lambda expression, what we want to do is we don't want this and we don't want this also.
So this is something which I don't really want.
What I want is I want to use this along with any functions, which is either map reduce or forgive.
OK, now let's try to understand what my buzz, what reveals does what filter does and how we can use
Langbein concurrence with this.
OK, you can use other functions also with my produce and up, but usually we use these lambda expressions,
one lambda expressions which we create and then we use my producer for that on top of that.
Now, let us understand what my producer enfolded is.
So let us talk about math.
OK, so what, Mark, does this map will simply try to map a function to when I tribal object.
OK, so it will map a function to an eye, to the object.
So this object could be a list.
It could be a table.
It could be anything.
So it is not really considered, but it could be either a list or a dictionary or anything like that.
So let's say we have a list in this case.
So let us create a list.
No.
And let this list contain values one one one three, four, five, six, seven, eight, nine, and
Graney five.
Nine, twenty six minutes.
And what I want to do is.
I simply want to.
Get these some of these values so I can get those also or what I want to get is instead of these values
legacy, I just want to get something like.
I want to simply get the.
Squares of these values, let us say, I want to get these squares with these values so I can use map.
And what I want to map, I need to give a function which I want to map, so let us say I have a function
squit.
OK, this is a function which basically runs the square of a number which I put in, and I want to map
it to the numbers, the numbers which I have.
OK, so I want to apply this on numbers.
This is this infix of MUF.
OK, what I can do is I can get the values using mapping this entire thing to a list so I can map this
entire thing to a list and get these values as an output.
So let us create a function square first.
So this square function I want to generate using the expression.
So instead of writing Square, what I can do is.
I can simply say Lamda.
And what do we give up, the land that we give the number?
The argument which it needs to have, so let's say we want to give it.
And what do you want to do?
Do you want to get a squared off?
OK, so we simply say do the power.
So this will give the squared off as the result.
And this is the function which we want to have.
This is the function that you want to have.
And this is the object on top of which we want to apply this function.
OK, so what will happen when we run this?
It is such a huge square, so let us have a smaller number here.
There does have.
A number like this, instead of giving aid to the power, we just need to give a square.
OK, this is the square of the number.
Now, if you're to a point now, see, what it does is it vibrates over the entire list.
It has one, two, three, four, five, six, seven, eight.
So it goes to one.
It takes one.
It finds out we need to do a square of it.
And it then goes to the next number, finds a square and puts it next number, finds the square and
makes no finds us.
It does the entire thing.
This is what we get from the map and.
The list, which we have applied on top of it, converted into a list for.
OK, so we can apply any kind of function here.
OK, now let us say instead of this, what I want to do is I just want to have numbers.
Let us do another trial on top of it.
I want to get this number and I want to multiply some number with some other numbers.
So let's say I have this number one.
This is one list and I have another list of number two, which is the second number list, which I want
to have.
And I want to multiply this in the first list with the second list.
And here I have nine numbers, so let's have another number.
So I want to multiply this entire list with latency just then, but it could be any list of numbers.
So this is three, this is three, and this is three, so now I instead of multiplying this with this,
I want to multiply it with the.
So I give me here and now this is the first argument, number one, and the second argument is number.
So this is the function which I am want to map and what are the values which I want to map, which I
want to map, number one.
And number two, and what are these number one number?
These are the values and we will be doing so if I run this.
You get these values.
So it just taking raising it to the public, if I do simple multiplication, get the isn't.
So you can apply any kind of function using this map.
This is what my function does.
Now, let us try to understand what Filter does, OK?
So let us go to filter.
So the filter function returns and ideato OK, which yields the items of the approval for which the
function is true.
OK, so talking in the layman's language center will simply apply a filter on top of the object.
OK, so let's see.
I again have these numbers say no.
OK, I have this number again.
OK, I have these number one, so I want to apply for it so that it will give me not only the even values
of only the old values.
OK, so I can filter out these values and get only the values which I want out of this.
This is what freedom does.
OK, so what we can do is.
We can simply create a function.
OK, let us create a function which is checking if one number is even or not.
OK, so let us define a function.
Gay.
Even our.
And we are giving No.
And what do we want to do?
We want to do it on.
If when the number is.
Divided by two, is it zero or not?
OK, if it is returning zero, that means it does.
Even if it is not returning zero, then it means that this.
Or so I'm giving it a zero.
OK, now.
We have this.
On top of this now, I want to apply for you go on inside this building.
Again, what I need to give is I want to give the function, but I want to use to feel that the.
The will object, which I have, so I have this even I and I have this number is number one with me
now.
This even is not exactly a function.
It is just a boolean expression, right?
It is a boolean expression which will either give me a true or false kind of value.
If the value is zero, it means that it is false if the value is other than zero.
It means that it is true, so whatever value we have through it will simply mean that the expression
is true and that particular value will come out of it.
If the value is false, then the value will not be coming out of the fear that it will get filled up.
It will just be struck that OK, so let us run this.
So it gives me this filtered object.
Now, what I can do is I can simply apply a list on top of it to get the values out of this.
So when I done this, I get the even values.
OK, so this is what my filter does now instead, if you don't really want to use this, even because
we are using lambda functions, we want to use lambda functions.
So what we can do is instead of writing this entire thing and writing the function and everything,
we can simply do it this way.
We can write the lambda function again.
OK, the lambda function will take in value, so let us see it and we want to apply a function.
So now we will check.
If it is divided by two, then the remainder is equivalent to zero or not.
So if the remainder is equal to zero, this function becomes true and gives the value up.
So this is the same result using the lambda expression.
OK, now let us try the next thing, which is the videos.
So.
What reduced does is.
In case of produce, we will be able to retrieve some value, which is which is taken out from the continuous
application of a function honor I object Your Honor sequence.
So let me explain it to you.
So let us talk about your news and we can use map for the LAMDA without any import.
But when we are talking about produce, we need to import the photos.
So the first thing which we need is import functor so we can import this as Ifti, OK.
So this is one thing which we need.
Now how the deals works.
So let say I have a list of numbers, OK?
I have a list of numbers.
Say one comma.
Forty six former twenty three comma twenty four comma nine comma eight from a five.
Hundred one thousand eight, twenty three and two.
OK, now, if I want to find out what is the maximum number out of this.
Then how I can do it is.
One thing is I can apply the maximum function, but this is not the purpose here, I want to explain
how this works.
So what we can do is what we will be doing is we will be out the first two numbers and we will compare.
That is one greater or greater.
Now, here we get 46.
So 46 is the largest number out of these.
So what we will have.
We have this thing.
So in the next libration, what I will have is I will have something like, I will have just six hours.
Because this has again.
Changed.
OK, I will have this 46 now again, then I will be.
Running this next iteration, so it will again go ahead and check if 46 is bigger or 23.
Now, again, politics is bigger, so it will get rid of this 23 and we will have 46 in 10.
Then again, it will keep going.
And out of 46 and 34, it will give 46.
So this is what we will have.
Now, again, let's go to the next generation, so now it will compare what the six four nine, eight
five.
All of these will be compared.
So it will keep only 46.
Now, this would be like after several patients.
Now, in the next iteration, what will happen is if will compare four to six and hundreds again now
when it compares for the six, one hundred one hundred is again greater than four to six.
So it will be a hundred and it will keep doing this entire thing until this entire list is reduced to
just one number.
And that one number will be outmuscled.
This is what news is doing in.
OK, so let's try to apply this to.
OK, so let us have no.
And let these be the values of No.
And out of these numbers, what I want to do is I want to find out the max and what is Max Max's.
F.T. Don't reduce.
And what I want to do is I want to apply a lambda, I want to apply this lambda on equal, maybe there
would be do values on which the expression would be applied.
These two values will always be the force to values which we have.
So in the first iteration, it will be one four forty six.
In the next iteration it will be the result which will which we will get by applying the expression
on these two.
So we will get forty six out of this then it will apply.
In the the expression on forty six and twenty three, then as a result we will get forty six, then
applied on four to six and thirty four, then it will apply on forty six and nine, then it will again
check with forty six and eight, then forty six and five.
Then again it will take forty six and hundred.
Then it will take between forty six and hundred.
It will get one hundred as it is then it will take between hundred and one thousand and eight.
So it will find over one thousand eight as that result.
Then again it will take between one thousand eight hundred twenty three, it will get one thousand eight
as a result.
And then after comparing with two it will take one thousand eight.
So this is the entire thing which we will be which will be going on internally.
So it will do this.
And what it will do.
It will be done.
It is great than then be.
Ends it with.
Summerton v..
And it will run this entire thing.
Poll numbers.
OK, now let us run, Max.
So we get one thousand eight as it is in.
OK, now let's say we want to calculate some numbers from C one, two hundred, we can apply this again,
so let us see some.
Although if not reduce.
And what we want to do, we want to apply lamda, what is the lamda function doing?
It is adding e it is getting the value equal maybe, and it is doing a Lusby.
And it is doing this on.
Numbs our let us see range.
One to one hundred and one.
And let us Lonesome's so here we get some of numbers from one to one hundred and one.
Similarly, we could do anything like that.
We can maybe multiply these numbers.
We get something like that again.
And this we get this so you can apply any function.
But just need to remember how the deals works, how my books, how filter works.
So just to reiterate the entire thing, because it is a little complex in nature.
Map will apply this function on top of the list, which we will be providing, we can provide multiple
lists and these lists will correspond to each and every variable which you will be having.
So here no one will correspond to a number, will correspond to me.
So it gives me hives.
See, also then we can give any other list also as names to be anything like that could be done.
So there is no specific restriction on how many variables you need to have in your lambda expression.
My function will just apply a function on all the elements of the iterable object.
Fater will apply.
Expression, alumni expression, which will be giving a boolean value or.
Numeric value as a design, which will be if it is zero, it will mean that it is false.
If it is non-zero, it will mean that it is true and for whatever value for which the desired of the
expression is coming through, that will be given out as a.
And what reduced does this reduce will loop over the entire apremilast?
With a set of two values, so it will run on the top of these two and produce these two values into
one value, then pick out the next value and.
Keep on doing the entire thing.
It has introduced the entire iterable list in just one single value, and that value comes out as the
deciding this is what my produce folder is and this is how we use it.
You can try different things, you can try different.
Samples for this, you can try different ways for this, you can apply different expressions and triangulate
on how this works.