Why use lambda python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why use lambda python

What is the advantage of creating lambdas in python? I have the impression that we are creating non-reusable code.

17th Sep 2022, 6:39 AM
Roland
Roland - avatar
5 Answers
+ 6
yes your impression is correct! But sometimes we need a function only once (lets say as key for sorting or a filter function). In this cases it is a shortpath to defining functions.
17th Sep 2022, 7:44 AM
Oma Falk
Oma Falk - avatar
+ 3
Ig it really depends on the situation!! Sometimes you want a one time use function, instead of creating a real function and naming it , u can just use lamda and be done.... For eg.. if you wanna call a function within a function with a condition then you can use lamda or it is very useful if you want to reduce the total lines of code...
17th Sep 2022, 9:10 AM
Dam Bro
Dam Bro - avatar
+ 3
Roland yes. One might need map and filter for better understanding of lambdas.
17th Sep 2022, 1:03 PM
Oma Falk
Oma Falk - avatar
+ 1
Thanks a lot 👍! I have also understood better with the Map and filter methods on next python lesson 😄
17th Sep 2022, 11:57 AM
Roland
Roland - avatar
0
Surely the point of any function is that you can reuse it, doesn't lambda functions get away from this. So I am lost on there purpose other than to make code unreadable! Surely it is better to spend time and create reusable functions.
18th Sep 2022, 11:03 AM
Gray Adamson
Gray Adamson - avatar