|
|
|
|
|
by danio
5700 days ago
|
|
Is there much benefit to fact = lambda n: _if (n <= 1) (1) (lambda: n * fact(n-1))
over def fact(n):
if (n <= 1):
return 1
else:
return n * fact(n-1)
1 line vs 5 lines doesn't seem like an advantage to me when it takes pretty much the same amount of time to read and understand the complicated 1 liner.Is there more optimisation possible? |
|
When the code is primarily expressions, it's relatively easy to to this. Trying to do one-liners with regular python syntax can get tricky.
Also, if you have a series of similar relationships to present, it's often easier to line them up next to each other. You might cut 12 lines to 6 lines and the whole thing will be far clearer. Although in those cases, it's probably more effective to use a dictionary to achieve the same thing, with the advantage of data/logic separation.