+ 1
When should we use lambda function
Is it different bcz it's written in one or is there any other difference too
8 Answers
+ 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.
+ 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)
+ 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 đŹ
+ 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.
+ 2
David Ashton ~ swim ~ best answers guys
I understood what and when to use lambda
0
Any particular instance where o should and shouldn't be using it
0
Just a thought, may be user defined function easier to debug!