Добавить
Уведомления

Python tutorial | Python tutorial for beginners | python | Comp, Lambda, Map, Reduce & Filter | S09

The lambda operator or lambda function is a way to create small anonymous functions, i.e. functions without a name. These functions are throw-away functions, i.e. they are just needed where they have been created. Lambda functions are mainly used in combination with the functions filter(), map() and reduce(). The lambda feature was added to Python due to the demand from Lisp programmers. The general syntax of a lambda function is quite simple: lambda argument_list: expression The argument list consists of a comma separated list of arguments and the expression is an arithmetic expression using these arguments. You can assign the function to a variable to give it a name. The function filter(function, list) offers an elegant way to filter out all the elements of a list, for which the function function returns True. The function filter(f,l) needs a function f as its first argument. f returns a Boolean value, i.e. either True or False. This function will be applied to every element of the list l. Only if f returns True will the element of the list be included in the result list. The function reduce(func, seq) continually applies the function func() to the sequence seq. It returns a single value. If seq = [ s1, s2, s3, ... , sn ], calling reduce(func, seq) works like this: At first the first two elements of seq will be applied to func, i.e. func(s1,s2) The list on which reduce() works looks now like this: [ func(s1, s2), s3, ... , sn ] In the next step func will be applied on the previous result and the third element of the list, i.e. func(func(s1, s2),s3) The list looks like this now: [ func(func(s1, s2),s3), ... , sn ] Continue like this until just one element is left and return this element as the result of reduce() The advantage of the lambda operator can be seen when it is used in combination with the map() function. map() is a function with two arguments: r = map(func, seq) Disclaimer: It doesn't feel good to have a disclaimer in every video but this is how the world is right now. All videos are for educational purpose and use them wisely. Any video may have a slight mistake, please take decisions based on your research. Share, Support, Likes, Subscribe!!! About : ITinfra Academi is a YouTube Channel, where you will find technological skill videos for Career growth/Career change. New Video is Posted Everyday/AlternateDay/EveryWeek/EveryMonth. ©COPYRIGHT. ALL RIGHTS RESERVED. #pythontutorial #python #pythontutorialforbeginners #pythonprogramming #pythonforbeginners #learnpython #pythonbydurgasir #pythonprojects #numpypythontutorial #pandaspythontutorial #pythonfullcourse #machinelearningpython #pythontutorials #pythonfordatascience

Иконка канала Введение в Python
4 подписчика
12+
16 просмотров
2 года назад
12+
16 просмотров
2 года назад

The lambda operator or lambda function is a way to create small anonymous functions, i.e. functions without a name. These functions are throw-away functions, i.e. they are just needed where they have been created. Lambda functions are mainly used in combination with the functions filter(), map() and reduce(). The lambda feature was added to Python due to the demand from Lisp programmers. The general syntax of a lambda function is quite simple: lambda argument_list: expression The argument list consists of a comma separated list of arguments and the expression is an arithmetic expression using these arguments. You can assign the function to a variable to give it a name. The function filter(function, list) offers an elegant way to filter out all the elements of a list, for which the function function returns True. The function filter(f,l) needs a function f as its first argument. f returns a Boolean value, i.e. either True or False. This function will be applied to every element of the list l. Only if f returns True will the element of the list be included in the result list. The function reduce(func, seq) continually applies the function func() to the sequence seq. It returns a single value. If seq = [ s1, s2, s3, ... , sn ], calling reduce(func, seq) works like this: At first the first two elements of seq will be applied to func, i.e. func(s1,s2) The list on which reduce() works looks now like this: [ func(s1, s2), s3, ... , sn ] In the next step func will be applied on the previous result and the third element of the list, i.e. func(func(s1, s2),s3) The list looks like this now: [ func(func(s1, s2),s3), ... , sn ] Continue like this until just one element is left and return this element as the result of reduce() The advantage of the lambda operator can be seen when it is used in combination with the map() function. map() is a function with two arguments: r = map(func, seq) Disclaimer: It doesn't feel good to have a disclaimer in every video but this is how the world is right now. All videos are for educational purpose and use them wisely. Any video may have a slight mistake, please take decisions based on your research. Share, Support, Likes, Subscribe!!! About : ITinfra Academi is a YouTube Channel, where you will find technological skill videos for Career growth/Career change. New Video is Posted Everyday/AlternateDay/EveryWeek/EveryMonth. ©COPYRIGHT. ALL RIGHTS RESERVED. #pythontutorial #python #pythontutorialforbeginners #pythonprogramming #pythonforbeginners #learnpython #pythonbydurgasir #pythonprojects #numpypythontutorial #pandaspythontutorial #pythonfullcourse #machinelearningpython #pythontutorials #pythonfordatascience

, чтобы оставлять комментарии