Hacker News new | ask | show | jobs
by frenchyatwork 2213 days ago
I'm sure there are cases where multiple lines would be nice, but I don't think this is one. This seems easier to read to me:

    lambda i: -i * i if i < 0 else i * i
Also, the functional way of doing multiple lines in a lot of situations would typically be to compose smaller lambdas.
2 comments

Yeah, this is a trivial example. I picked it specifically to show that multi-line lambdas don't have to be stateful, not as an example of a lambda that couldn't be written in one line.
And there is math.copysign