+ 2
Why we use lambda instead of creating a function??
i think its better to create function then using lambda..
5 odpowiedzi
+ 3
Lambdas are generally used for one-time operations. If you plan to use the same generator many times, define it as a function. If not, lambda is your friend :)
+ 2
1. Inline so you don't have to define separately before using
2. Inline so you don't have to think out a name for it!
+ 1
i think easier in short term and better as a memory wise
0
You can use them as arguments in other functions. Google callback functions, function passing style and functions as first class citizens.
0
I have never seen a lambda function used outside of code golf challenges, so the honest answer is that you don't. I think lambda's themselves are being slowly phased out of Python because they're so heavily neglected.
That said, you should try to understand the concepts behind them, even if you'll never use them.