3 ms·
what's so hard about >>> (lambda x: x+1 if \ ... True \ ... else x+x)\ ... (10) 11 :p
by agumonkey 5y ago
what's so hard about
>>> (lambda x: x+1 if \
... True \
... else x+x)\
... (10)
11
:p
- lvass 5y agoNow try including if statements, loops, structural pattern matches, context managers, etc.
- jstx1 5y agoIf it's too complicated for a lambda, you shouldn't be using a lambda. Define a separate function if it takes you more than a line or it's harder to reason about.
- lvass 5y agoThe point is it's only complicated in Python. In other languages, like Rust, it's idiomatic.
- agumonkey 5y agoPeople all know lambdas are expressions only, it's not a biggie really. In all honesty you rarely inline complex lambdas with all you mentioned, it would become hard to read or debug.