WEBVTT

00:00.950 --> 00:09.470
Right now, we would talk about the lamda functions and how we can use them along with MAP Reduce and

00:09.470 --> 00:09.950
fatal.

00:10.980 --> 00:15.450
So first of all, let us discuss what lambda functions actually are.

00:16.380 --> 00:27.420
Lambda functions are one of the python's most useful tools and these are really very difficult and confusing

00:27.540 --> 00:28.550
for the beginners.

00:29.190 --> 00:34.950
So it is very important to pay attention and understand this concept, because once you understand this,

00:34.950 --> 00:36.360
it will be very helpful.

00:38.380 --> 00:48.520
So no function is used to create anonymous functions, so we have been using the def keyboard to create

00:48.520 --> 00:57.990
different functions, I would create a function system and this would basically help me to add to numbers.

00:58.030 --> 01:00.250
So let's say I have no equal maybe.

01:00.520 --> 01:02.170
And I would simply say.

01:03.320 --> 01:13.370
The tone and I would say A plus B, so this function would allow me to read on the some of these two

01:13.380 --> 01:21.050
values so I can any time you sums and give the two there, one or two, and it will simply give me the

01:21.050 --> 01:21.980
result of this thing.

01:23.370 --> 01:32.900
Now it is very easy to use this and it might be a little of you can say find the woman to write this

01:33.230 --> 01:38.060
function and maybe I might use this several number of times.

01:39.210 --> 01:45.210
But there could be a situation when I don't really want to you several functions.

01:45.420 --> 01:48.960
I do want to keep the method aside.

01:49.080 --> 01:56.970
I do want to keep the functionality aside, but I don't really want to reuse this thing again and again.

01:57.180 --> 02:03.390
So what I can do is I can quickly create a small function, which I can use at that time and then completely

02:03.390 --> 02:04.130
forget about.

02:04.920 --> 02:08.250
So that is what lamda function allows me to.

02:10.440 --> 02:16.420
So Lamda is a single expression and it is not a block statement.

02:16.650 --> 02:22.170
So usually when we have the lambda functions or let's say when we have any of the functions.

02:33.300 --> 02:39.340
Let us say I am creating this function sum's, so I am writing these three lines of code.

02:39.930 --> 02:46.620
But in case of a lambda expression it I don't need to write these so many lines of code.

02:46.620 --> 02:49.440
I just need to write a small expression here.

02:50.030 --> 02:56.580
OK, so let us see how we can construct this lambda expression and how we can use this.

02:57.290 --> 02:59.430
OK, so let us see.

02:59.430 --> 03:00.960
I want to create.

03:02.280 --> 03:07.080
Alamdar function, so what I can simply do is I can send these right lamda.

03:09.180 --> 03:18.780
And with Lamda, I want to read the argument, which I want to give, so let us say I want to have equal

03:18.810 --> 03:22.440
maybe these are the two arguments which I wanted to be.

03:23.190 --> 03:29.760
And what I want to give out of what I want to now is what I write next up of this.

03:30.390 --> 03:31.470
So I give all.

03:31.710 --> 03:33.950
And after this I simply say E-Plus.

03:34.500 --> 03:39.420
So I just want to read on E-Plus V and A and B is what I'm speaking from.

03:40.380 --> 03:47.340
So this is a very small lambi expression which I can use any number of times.

03:48.090 --> 03:53.340
OK, now this lambda expression V will not be using like this.

03:54.330 --> 03:57.460
OK, we will not be giving any lame name to it.

03:57.630 --> 04:00.030
So what I can do is I can see something like.

04:01.260 --> 04:02.680
See love.

04:04.140 --> 04:15.470
And I can create this kind of thing, so whenever I do something Laci, I do and I give simplicity to

04:15.480 --> 04:19.080
grandma if I do it so it will give the desired back to me.

04:19.090 --> 04:21.560
But this is what I actually don't want to do.

04:21.570 --> 04:23.160
I don't want to give anything to it.

04:23.400 --> 04:28.080
This is the main concept of lamda function that I don't want to create a mean function.

04:28.470 --> 04:32.130
If I wanted to create a new function, I would have used this only.

04:32.990 --> 04:40.860
OK, so for lambda expression, what we want to do is we don't want this and we don't want this also.

04:41.840 --> 04:44.130
So this is something which I don't really want.

04:44.630 --> 04:54.710
What I want is I want to use this along with any functions, which is either map reduce or forgive.

04:55.490 --> 05:03.080
OK, now let's try to understand what my buzz, what reveals does what filter does and how we can use

05:03.080 --> 05:04.700
Langbein concurrence with this.

05:05.910 --> 05:13.920
OK, you can use other functions also with my produce and up, but usually we use these lambda expressions,

05:13.920 --> 05:18.990
one lambda expressions which we create and then we use my producer for that on top of that.

05:19.260 --> 05:22.220
Now, let us understand what my producer enfolded is.

05:22.260 --> 05:25.300
So let us talk about math.

05:26.820 --> 05:37.920
OK, so what, Mark, does this map will simply try to map a function to when I tribal object.

05:38.400 --> 05:46.840
OK, so it will map a function to an eye, to the object.

05:47.340 --> 05:49.370
So this object could be a list.

05:49.380 --> 05:50.270
It could be a table.

05:50.280 --> 05:51.580
It could be anything.

05:52.320 --> 05:57.610
So it is not really considered, but it could be either a list or a dictionary or anything like that.

05:57.870 --> 06:00.200
So let's say we have a list in this case.

06:00.390 --> 06:02.430
So let us create a list.

06:03.460 --> 06:04.000
No.

06:06.030 --> 06:15.030
And let this list contain values one one one three, four, five, six, seven, eight, nine, and

06:15.450 --> 06:16.290
Graney five.

06:17.880 --> 06:19.020
Nine, twenty six minutes.

06:20.010 --> 06:22.800
And what I want to do is.

06:23.750 --> 06:25.400
I simply want to.

06:26.550 --> 06:33.930
Get these some of these values so I can get those also or what I want to get is instead of these values

06:33.930 --> 06:36.600
legacy, I just want to get something like.

06:37.530 --> 06:39.120
I want to simply get the.

06:40.300 --> 06:47.320
Squares of these values, let us say, I want to get these squares with these values so I can use map.

06:48.940 --> 06:57.430
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

06:57.790 --> 06:58.330
squit.

07:00.220 --> 07:08.770
OK, this is a function which basically runs the square of a number which I put in, and I want to map

07:08.770 --> 07:11.090
it to the numbers, the numbers which I have.

07:11.840 --> 07:15.370
OK, so I want to apply this on numbers.

07:16.060 --> 07:18.310
This is this infix of MUF.

07:19.540 --> 07:29.230
OK, what I can do is I can get the values using mapping this entire thing to a list so I can map this

07:29.230 --> 07:33.140
entire thing to a list and get these values as an output.

07:33.580 --> 07:37.470
So let us create a function square first.

07:37.720 --> 07:42.130
So this square function I want to generate using the expression.

07:42.610 --> 07:45.280
So instead of writing Square, what I can do is.

07:46.910 --> 07:48.410
I can simply say Lamda.

07:50.040 --> 07:53.300
And what do we give up, the land that we give the number?

07:53.400 --> 07:57.000
The argument which it needs to have, so let's say we want to give it.

07:59.630 --> 08:00.790
And what do you want to do?

08:00.820 --> 08:03.480
Do you want to get a squared off?

08:03.960 --> 08:08.150
OK, so we simply say do the power.

08:09.080 --> 08:12.310
So this will give the squared off as the result.

08:12.590 --> 08:15.380
And this is the function which we want to have.

08:15.390 --> 08:17.020
This is the function that you want to have.

08:17.240 --> 08:22.610
And this is the object on top of which we want to apply this function.

08:23.240 --> 08:26.600
OK, so what will happen when we run this?

08:32.320 --> 08:36.330
It is such a huge square, so let us have a smaller number here.

08:37.330 --> 08:38.890
There does have.

08:40.210 --> 08:45.520
A number like this, instead of giving aid to the power, we just need to give a square.

08:50.740 --> 08:52.550
OK, this is the square of the number.

08:53.620 --> 09:01.120
Now, if you're to a point now, see, what it does is it vibrates over the entire list.

09:01.360 --> 09:03.630
It has one, two, three, four, five, six, seven, eight.

09:04.240 --> 09:05.650
So it goes to one.

09:05.650 --> 09:06.550
It takes one.

09:07.210 --> 09:10.990
It finds out we need to do a square of it.

09:11.320 --> 09:17.560
And it then goes to the next number, finds a square and puts it next number, finds the square and

09:17.560 --> 09:18.610
makes no finds us.

09:19.140 --> 09:20.470
It does the entire thing.

09:21.670 --> 09:24.670
This is what we get from the map and.

09:26.550 --> 09:31.210
The list, which we have applied on top of it, converted into a list for.

09:32.340 --> 09:35.460
OK, so we can apply any kind of function here.

09:35.910 --> 09:41.370
OK, now let us say instead of this, what I want to do is I just want to have numbers.

09:41.790 --> 09:44.500
Let us do another trial on top of it.

09:44.700 --> 09:50.680
I want to get this number and I want to multiply some number with some other numbers.

09:50.680 --> 09:53.610
So let's say I have this number one.

09:53.790 --> 09:59.790
This is one list and I have another list of number two, which is the second number list, which I want

09:59.790 --> 10:00.150
to have.

10:00.480 --> 10:04.290
And I want to multiply this in the first list with the second list.

10:04.740 --> 10:08.700
And here I have nine numbers, so let's have another number.

10:10.140 --> 10:16.350
So I want to multiply this entire list with latency just then, but it could be any list of numbers.

10:22.800 --> 10:32.940
So this is three, this is three, and this is three, so now I instead of multiplying this with this,

10:32.940 --> 10:34.560
I want to multiply it with the.

10:35.860 --> 10:43.620
So I give me here and now this is the first argument, number one, and the second argument is number.

10:46.720 --> 10:53.860
So this is the function which I am want to map and what are the values which I want to map, which I

10:53.860 --> 10:56.230
want to map, number one.

10:57.550 --> 11:01.450
And number two, and what are these number one number?

11:01.870 --> 11:06.580
These are the values and we will be doing so if I run this.

11:07.680 --> 11:09.690
You get these values.

11:12.250 --> 11:19.120
So it just taking raising it to the public, if I do simple multiplication, get the isn't.

11:21.090 --> 11:24.450
So you can apply any kind of function using this map.

11:25.820 --> 11:28.170
This is what my function does.

11:29.110 --> 11:33.660
Now, let us try to understand what Filter does, OK?

11:34.890 --> 11:38.640
So let us go to filter.

11:40.680 --> 11:49.560
So the filter function returns and ideato OK, which yields the items of the approval for which the

11:49.560 --> 11:50.790
function is true.

11:51.270 --> 12:00.210
OK, so talking in the layman's language center will simply apply a filter on top of the object.

12:00.870 --> 12:02.430
OK, so let's see.

12:02.430 --> 12:04.960
I again have these numbers say no.

12:05.340 --> 12:07.150
OK, I have this number again.

12:08.450 --> 12:15.650
OK, I have these number one, so I want to apply for it so that it will give me not only the even values

12:15.650 --> 12:17.300
of only the old values.

12:17.570 --> 12:23.480
OK, so I can filter out these values and get only the values which I want out of this.

12:23.840 --> 12:25.220
This is what freedom does.

12:25.910 --> 12:28.310
OK, so what we can do is.

12:29.900 --> 12:31.670
We can simply create a function.

12:32.010 --> 12:37.460
OK, let us create a function which is checking if one number is even or not.

12:37.810 --> 12:41.720
OK, so let us define a function.

12:43.190 --> 12:43.580
Gay.

12:44.900 --> 12:45.730
Even our.

12:47.780 --> 12:50.480
And we are giving No.

12:52.300 --> 12:53.600
And what do we want to do?

12:55.060 --> 12:56.050
We want to do it on.

12:57.750 --> 12:59.700
If when the number is.

13:01.340 --> 13:04.490
Divided by two, is it zero or not?

13:04.700 --> 13:07.730
OK, if it is returning zero, that means it does.

13:07.730 --> 13:11.840
Even if it is not returning zero, then it means that this.

13:12.780 --> 13:16.020
Or so I'm giving it a zero.

13:16.950 --> 13:18.600
OK, now.

13:19.940 --> 13:20.900
We have this.

13:22.550 --> 13:28.310
On top of this now, I want to apply for you go on inside this building.

13:28.340 --> 13:34.670
Again, what I need to give is I want to give the function, but I want to use to feel that the.

13:36.500 --> 13:48.290
The will object, which I have, so I have this even I and I have this number is number one with me

13:49.220 --> 13:49.550
now.

13:49.550 --> 13:53.500
This even is not exactly a function.

13:53.660 --> 13:56.510
It is just a boolean expression, right?

13:56.720 --> 14:01.760
It is a boolean expression which will either give me a true or false kind of value.

14:01.940 --> 14:07.250
If the value is zero, it means that it is false if the value is other than zero.

14:08.260 --> 14:17.440
It means that it is true, so whatever value we have through it will simply mean that the expression

14:17.440 --> 14:20.980
is true and that particular value will come out of it.

14:21.190 --> 14:27.110
If the value is false, then the value will not be coming out of the fear that it will get filled up.

14:27.400 --> 14:33.060
It will just be struck that OK, so let us run this.

14:33.940 --> 14:35.730
So it gives me this filtered object.

14:36.130 --> 14:41.530
Now, what I can do is I can simply apply a list on top of it to get the values out of this.

14:44.070 --> 14:48.540
So when I done this, I get the even values.

14:49.890 --> 14:57.960
OK, so this is what my filter does now instead, if you don't really want to use this, even because

14:57.960 --> 15:01.070
we are using lambda functions, we want to use lambda functions.

15:01.290 --> 15:05.730
So what we can do is instead of writing this entire thing and writing the function and everything,

15:06.150 --> 15:09.740
we can simply do it this way.

15:10.140 --> 15:11.910
We can write the lambda function again.

15:12.990 --> 15:19.390
OK, the lambda function will take in value, so let us see it and we want to apply a function.

15:19.410 --> 15:20.820
So now we will check.

15:20.820 --> 15:26.850
If it is divided by two, then the remainder is equivalent to zero or not.

15:26.860 --> 15:31.850
So if the remainder is equal to zero, this function becomes true and gives the value up.

15:32.950 --> 15:37.330
So this is the same result using the lambda expression.

15:39.430 --> 15:47.170
OK, now let us try the next thing, which is the videos.

15:48.480 --> 15:49.020
So.

15:50.440 --> 15:52.390
What reduced does is.

15:55.320 --> 16:06.600
In case of produce, we will be able to retrieve some value, which is which is taken out from the continuous

16:06.900 --> 16:11.340
application of a function honor I object Your Honor sequence.

16:11.670 --> 16:13.580
So let me explain it to you.

16:14.100 --> 16:25.860
So let us talk about your news and we can use map for the LAMDA without any import.

16:26.100 --> 16:31.400
But when we are talking about produce, we need to import the photos.

16:31.650 --> 16:43.550
So the first thing which we need is import functor so we can import this as Ifti, OK.

16:44.100 --> 16:45.640
So this is one thing which we need.

16:45.990 --> 16:47.660
Now how the deals works.

16:48.000 --> 16:51.700
So let say I have a list of numbers, OK?

16:51.960 --> 16:53.430
I have a list of numbers.

16:53.430 --> 16:55.550
Say one comma.

16:55.650 --> 17:03.120
Forty six former twenty three comma twenty four comma nine comma eight from a five.

17:04.220 --> 17:10.950
Hundred one thousand eight, twenty three and two.

17:12.630 --> 17:19.380
OK, now, if I want to find out what is the maximum number out of this.

17:20.580 --> 17:22.230
Then how I can do it is.

17:23.590 --> 17:29.020
One thing is I can apply the maximum function, but this is not the purpose here, I want to explain

17:29.020 --> 17:29.990
how this works.

17:30.970 --> 17:38.050
So what we can do is what we will be doing is we will be out the first two numbers and we will compare.

17:38.740 --> 17:42.130
That is one greater or greater.

17:42.670 --> 17:44.330
Now, here we get 46.

17:44.620 --> 17:49.050
So 46 is the largest number out of these.

17:50.180 --> 17:51.500
So what we will have.

17:52.740 --> 17:53.670
We have this thing.

17:54.910 --> 18:03.480
So in the next libration, what I will have is I will have something like, I will have just six hours.

18:05.290 --> 18:09.430
Because this has again.

18:10.430 --> 18:10.910
Changed.

18:11.860 --> 18:16.390
OK, I will have this 46 now again, then I will be.

18:17.650 --> 18:26.020
Running this next iteration, so it will again go ahead and check if 46 is bigger or 23.

18:26.500 --> 18:31.950
Now, again, politics is bigger, so it will get rid of this 23 and we will have 46 in 10.

18:33.190 --> 18:35.220
Then again, it will keep going.

18:36.160 --> 18:39.250
And out of 46 and 34, it will give 46.

18:40.790 --> 18:42.590
So this is what we will have.

18:44.510 --> 18:51.740
Now, again, let's go to the next generation, so now it will compare what the six four nine, eight

18:51.740 --> 18:52.250
five.

18:52.490 --> 18:53.940
All of these will be compared.

18:54.500 --> 18:56.280
So it will keep only 46.

18:57.650 --> 19:00.830
Now, this would be like after several patients.

19:02.210 --> 19:08.840
Now, in the next iteration, what will happen is if will compare four to six and hundreds again now

19:08.900 --> 19:13.250
when it compares for the six, one hundred one hundred is again greater than four to six.

19:13.430 --> 19:23.240
So it will be a hundred and it will keep doing this entire thing until this entire list is reduced to

19:23.240 --> 19:24.440
just one number.

19:24.770 --> 19:27.790
And that one number will be outmuscled.

19:31.080 --> 19:33.870
This is what news is doing in.

19:34.860 --> 19:38.030
OK, so let's try to apply this to.

19:39.850 --> 19:43.810
OK, so let us have no.

19:45.500 --> 19:48.890
And let these be the values of No.

19:52.610 --> 19:59.510
And out of these numbers, what I want to do is I want to find out the max and what is Max Max's.

20:01.150 --> 20:03.430
F.T. Don't reduce.

20:04.400 --> 20:13.610
And what I want to do is I want to apply a lambda, I want to apply this lambda on equal, maybe there

20:13.640 --> 20:16.710
would be do values on which the expression would be applied.

20:17.030 --> 20:20.430
These two values will always be the force to values which we have.

20:20.690 --> 20:24.470
So in the first iteration, it will be one four forty six.

20:24.620 --> 20:31.130
In the next iteration it will be the result which will which we will get by applying the expression

20:31.130 --> 20:31.860
on these two.

20:32.240 --> 20:35.480
So we will get forty six out of this then it will apply.

20:36.550 --> 20:44.880
In the the expression on forty six and twenty three, then as a result we will get forty six, then

20:45.250 --> 20:53.680
applied on four to six and thirty four, then it will apply on forty six and nine, then it will again

20:53.680 --> 20:56.890
check with forty six and eight, then forty six and five.

20:57.190 --> 21:00.220
Then again it will take forty six and hundred.

21:00.550 --> 21:04.480
Then it will take between forty six and hundred.

21:04.480 --> 21:11.110
It will get one hundred as it is then it will take between hundred and one thousand and eight.

21:11.710 --> 21:14.900
So it will find over one thousand eight as that result.

21:15.370 --> 21:20.650
Then again it will take between one thousand eight hundred twenty three, it will get one thousand eight

21:20.650 --> 21:21.210
as a result.

21:21.400 --> 21:24.820
And then after comparing with two it will take one thousand eight.

21:25.480 --> 21:29.050
So this is the entire thing which we will be which will be going on internally.

21:29.470 --> 21:31.240
So it will do this.

21:32.910 --> 21:34.650
And what it will do.

21:36.000 --> 21:36.960
It will be done.

21:44.350 --> 21:46.390
It is great than then be.

21:49.800 --> 21:51.590
Ends it with.

21:52.590 --> 21:53.560
Summerton v..

21:55.300 --> 21:57.460
And it will run this entire thing.

21:58.510 --> 22:00.070
Poll numbers.

22:01.440 --> 22:04.320
OK, now let us run, Max.

22:06.480 --> 22:09.120
So we get one thousand eight as it is in.

22:10.900 --> 22:19.410
OK, now let's say we want to calculate some numbers from C one, two hundred, we can apply this again,

22:19.900 --> 22:21.940
so let us see some.

22:25.990 --> 22:28.720
Although if not reduce.

22:29.850 --> 22:35.640
And what we want to do, we want to apply lamda, what is the lamda function doing?

22:35.970 --> 22:43.500
It is adding e it is getting the value equal maybe, and it is doing a Lusby.

22:44.850 --> 22:46.350
And it is doing this on.

22:48.110 --> 22:52.030
Numbs our let us see range.

22:54.080 --> 22:57.350
One to one hundred and one.

22:59.300 --> 23:08.370
And let us Lonesome's so here we get some of numbers from one to one hundred and one.

23:08.960 --> 23:10.790
Similarly, we could do anything like that.

23:10.800 --> 23:13.430
We can maybe multiply these numbers.

23:14.240 --> 23:16.260
We get something like that again.

23:16.290 --> 23:20.180
And this we get this so you can apply any function.

23:20.330 --> 23:27.560
But just need to remember how the deals works, how my books, how filter works.

23:27.710 --> 23:32.110
So just to reiterate the entire thing, because it is a little complex in nature.

23:33.570 --> 23:41.430
Map will apply this function on top of the list, which we will be providing, we can provide multiple

23:41.430 --> 23:47.920
lists and these lists will correspond to each and every variable which you will be having.

23:48.150 --> 23:53.910
So here no one will correspond to a number, will correspond to me.

23:54.120 --> 23:55.290
So it gives me hives.

23:55.290 --> 24:02.010
See, also then we can give any other list also as names to be anything like that could be done.

24:02.670 --> 24:07.680
So there is no specific restriction on how many variables you need to have in your lambda expression.

24:09.020 --> 24:16.160
My function will just apply a function on all the elements of the iterable object.

24:17.290 --> 24:19.360
Fater will apply.

24:20.700 --> 24:26.840
Expression, alumni expression, which will be giving a boolean value or.

24:27.940 --> 24:34.180
Numeric value as a design, which will be if it is zero, it will mean that it is false.

24:34.190 --> 24:40.260
If it is non-zero, it will mean that it is true and for whatever value for which the desired of the

24:40.600 --> 24:45.070
expression is coming through, that will be given out as a.

24:47.580 --> 24:54.660
And what reduced does this reduce will loop over the entire apremilast?

24:56.710 --> 25:04.750
With a set of two values, so it will run on the top of these two and produce these two values into

25:04.750 --> 25:08.920
one value, then pick out the next value and.

25:10.210 --> 25:11.740
Keep on doing the entire thing.

25:12.070 --> 25:20.440
It has introduced the entire iterable list in just one single value, and that value comes out as the

25:20.440 --> 25:25.770
deciding this is what my produce folder is and this is how we use it.

25:27.310 --> 25:31.360
You can try different things, you can try different.

25:33.650 --> 25:41.630
Samples for this, you can try different ways for this, you can apply different expressions and triangulate

25:41.630 --> 25:42.970
on how this works.
