4 ms·
The lambda thing is not about whitespace indentation. It is a purposeful decision that if you need more than one line to do it, it should have a name. At first
by larkost 5y ago
The lambda thing is not about whitespace indentation. It is a purposeful decision that if you need more than one line to do it, it should have a name.
At first I disliked this, but it does nudge you towards readability, which winds up to be a good thing. And if you look at it, there is very little space difference between an unnamed lambda and an embedded function:
def lambda_version():
a = lambda x:
line one
line two # note: this sort-of requires the idea of implicit return, which Python does not have outside of lambda
a()
def named_version():
def lambda_replacement():
line one
return line two
lambda_replacement()