4 ms·
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
by frenchyatwork 6y 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.
- saghm 6y agoYeah, 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.
- entha_saava 6y agoAnd there is math.copysign