+ 1

When should we use lambda function

Is it different bcz it's written in one or is there any other difference too

3rd Aug 2019, 5:31 PM
SUNDARAMAN IYER
SUNDARAMAN IYER - avatar
8 ответов
+ 8
We can, don't use it in principle, it just allows us to reduce the code. My opinion is better not to use it. But this is my opinion.
3rd Aug 2019, 5:38 PM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 8
My opinion is not to use this feature at all. Instead, write your own function that has a name. For example: def function(): return print(123)
3rd Aug 2019, 5:49 PM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 5
I generally prefer to use a comprehension wherever possible, e.g. using ~ swim ~'s example "lst = [1, 2, 3] say you want add 5 to each element in the list", instead of using res = list(map(lambda x: x+5, lst)) I would just use: res = [i+5 for i in lst] mainly because it's simple and readable, and I'm not crazy about adding extra words like "list", "map" and "lambda" that I have to scratch my head over 😬
4th Aug 2019, 4:13 AM
David Ashton
David Ashton - avatar
+ 4
One of lambda applications is in callback definition for gui widgets like buttons. simply those are inline functions and when we need a simple task to do, they are preferable in comparison with writing named functions and stack push /pop overheads.
3rd Aug 2019, 8:39 PM
Qasem
+ 2
David Ashton ~ swim ~ best answers guys I understood what and when to use lambda
4th Aug 2019, 4:41 AM
SUNDARAMAN IYER
SUNDARAMAN IYER - avatar
0
Any particular instance where o should and shouldn't be using it
3rd Aug 2019, 5:45 PM
SUNDARAMAN IYER
SUNDARAMAN IYER - avatar
0
Just a thought, may be user defined function easier to debug!
28th Aug 2019, 10:52 PM
\•/
\•/ - avatar