lambda Function…
lambda function is also known as anonymous function in python , basically it is unnamed and one line function. This function can have any number of argument but only one expression.
lambda arguments : expressionThink about this kind of scenario , you need a small function for short time period like using map() , filter() , sorted() functions ,so lambda function comes in that time.
This procedure makes clean and efficient code.Now we look some use cases ,
Get kalindu ranathunga’s stories in your inbox
Join Medium for free to get updates from this writer.
01) Understanding how it works :
addition = lambda x,y : x+Y
result = addition(3,4)02) lambda function with map() function
numbers = [ 1 , 2 , 3 , 4 ]
square_num = map(lambda x : x**2 , numbers)03) lambda function with filter() function
numbers = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
greater_than_five = filter(lambda x : x>5 , numbers)
![[ list ] Comprehension…](https://miro.medium.com/v2/resize:fit:1358/format:webp/1*v7p-Z1UKUa7GkCeFz-2kmQ.jpeg)
![[ list ] Comprehension…](https://miro.medium.com/v2/resize:fill:320:214/format:webp/1*v7p-Z1UKUa7GkCeFz-2kmQ.jpeg)




