1 00:00:00,330 --> 00:00:06,780 By anonymous or lamda function and anonymous function means there is a function which has got no name. 2 00:00:07,320 --> 00:00:11,670 So how do you define anonymous function or Landen function in Biton? 3 00:00:11,820 --> 00:00:14,320 We shall be discussing that one in this session. 4 00:00:14,850 --> 00:00:19,540 So in Python, the anonymous function is a function that is defined without having any name. 5 00:00:20,010 --> 00:00:25,890 So in normal function definitions, we use that the key word there is a defined tool and on the other 6 00:00:25,890 --> 00:00:30,740 end in Python, the anonymous functions are used using the lambda keyword. 7 00:00:31,410 --> 00:00:35,370 So hence anonymous functions are also called the lambda function. 8 00:00:35,410 --> 00:00:38,270 So in case of anonymous functions, there will be no name. 9 00:00:38,280 --> 00:00:44,490 So we are not using the key word def that is a defined and here will be using the keyword. 10 00:00:44,490 --> 00:00:45,540 That is that lambda. 11 00:00:45,840 --> 00:00:50,880 So I think it would be better to let us go for one demonstration to show you how to write the anonymous 12 00:00:50,880 --> 00:00:54,010 functions and then the lambda functions in our python coding. 13 00:00:54,980 --> 00:01:01,430 While defining ordinary functions, we use the key word, if there is a defined but in case of LAMDA 14 00:01:01,430 --> 00:01:04,100 function, we shall be using the key word lambda. 15 00:01:04,610 --> 00:01:10,580 So here we are having some set of examples to clear your doubts and to know that what is an anonymous 16 00:01:10,580 --> 00:01:12,230 function or a lambda function? 17 00:01:12,920 --> 00:01:19,540 So here you can find that lambda X, so X will be the input and it returns X start to that because the 18 00:01:19,540 --> 00:01:23,010 returns are double up to X and that has been assigned to a. 19 00:01:23,390 --> 00:01:29,540 So in Python, anonymous function is a function that is defined without the name and it is defined by 20 00:01:29,540 --> 00:01:30,800 the key word lambda. 21 00:01:31,310 --> 00:01:38,380 So now if we pass this 10 as input argument to this E, then obviously I'm supposed to get double often. 22 00:01:38,390 --> 00:01:42,650 So if I put my code, I can find that double of ten is 20. 23 00:01:43,010 --> 00:01:45,860 So here X is input and it returns. 24 00:01:45,860 --> 00:01:49,070 This external to that is a double of X here. 25 00:01:49,670 --> 00:01:51,110 So let us go for the another one. 26 00:01:51,650 --> 00:01:56,320 So making a new list by taking only the event numbers from the old list. 27 00:01:56,750 --> 00:01:58,340 So here is my old list. 28 00:01:58,340 --> 00:02:01,370 So it is my, my list and it is having are set up. 29 00:02:01,370 --> 00:02:06,800 Numbers are there and here you are using one method, one function that is known as a filter function, 30 00:02:07,160 --> 00:02:11,300 which is called with all the items in the list that is on my list. 31 00:02:11,430 --> 00:02:18,170 It will be it will be working on all the items of this my list, and it will create a new list which 32 00:02:18,170 --> 00:02:23,120 will be returned, which contains items for which the function evaluates. 33 00:02:23,270 --> 00:02:23,580 True. 34 00:02:23,600 --> 00:02:25,820 That means that we are having one condition. 35 00:02:26,090 --> 00:02:32,990 The condition will be true if X is an even number, because X percent D2 means that the remainder of 36 00:02:32,990 --> 00:02:34,400 the division of by two. 37 00:02:34,880 --> 00:02:41,630 If it is zero, that means if the number X is even number, then X percent is will be equal to zero, 38 00:02:41,960 --> 00:02:44,560 then the respective X will be returned. 39 00:02:44,870 --> 00:02:47,010 So now that will create a new list. 40 00:02:47,390 --> 00:02:53,690 So if I bring that new list, it will print here for six, eight and 12 respectively. 41 00:02:54,110 --> 00:02:56,140 So let us go for the output here. 42 00:02:56,480 --> 00:03:02,510 So if I execute on finding that the new list is having the value for six, eight and 12 because they 43 00:03:02,510 --> 00:03:05,510 are the only event numbers in this my list. 44 00:03:05,750 --> 00:03:10,970 So this filter is actually dealing with those numbers which will satisfy this condition. 45 00:03:11,180 --> 00:03:18,590 That is X percentage is is equal to zero and it will operate on a new list on my list and it will produce 46 00:03:18,620 --> 00:03:20,560 output in the new list here. 47 00:03:21,080 --> 00:03:24,180 So let's go for another example of this lambda function. 48 00:03:24,560 --> 00:03:30,290 So here you can see that a program to double each item in a list using the map. 49 00:03:30,300 --> 00:03:32,490 So here we are losing the method map here. 50 00:03:32,870 --> 00:03:38,870 So my list is having one, five, four, six, eight, 11, three and very arbitrary numbers we have 51 00:03:38,870 --> 00:03:39,580 mentioned here. 52 00:03:39,920 --> 00:03:45,920 Now we are having this lambda, which will take this X and it will return to Stridex and the values 53 00:03:45,920 --> 00:03:51,690 of X will be taken individually from this list that is on my list here and that will be mapped. 54 00:03:51,710 --> 00:03:58,280 So here we are using this method to map here, which will double each item in a list using this map 55 00:03:58,280 --> 00:03:58,760 method. 56 00:03:58,940 --> 00:04:02,700 And here the outcome is being done, the typecasting to list. 57 00:04:03,050 --> 00:04:05,840 So now the new list will be getting the list as well. 58 00:04:06,080 --> 00:04:07,450 So now what will be the output? 59 00:04:07,470 --> 00:04:08,990 So let's go for the execution. 60 00:04:09,000 --> 00:04:15,060 You can find that all the members in this particular list, there is a list, members have got doubled 61 00:04:15,200 --> 00:04:17,190 and that has been assigned to the new list. 62 00:04:17,510 --> 00:04:23,090 So this map is actually mapping this this lambda function to each and every element of this. 63 00:04:23,300 --> 00:04:29,540 My list and its outcome will be has been done typecast with this list method. 64 00:04:29,720 --> 00:04:31,910 And so that new list has been formed. 65 00:04:32,030 --> 00:04:34,800 And later we have printed the new list as well. 66 00:04:35,180 --> 00:04:39,350 So in this example, we have shown you that how to define lambda. 67 00:04:39,350 --> 00:04:42,000 That is the anonymous function in our Bitan. 68 00:04:42,590 --> 00:04:44,180 Thanks for watching this video.