[Tutor] Cannot Understand

Anna Ravenscroft annaraven at gmail.com
Sat Mar 11 02:14:07 CET 2006


On 3/10/06, Alan Gauld <alan.gauld at freenet.co.uk> wrote:
>
> >> Could you please explain this code?.
> >>
> >> f = lambda n: n-1 + abs(n-1) and f(n-1)*n or 1
> >
> >
> >This is why lambdas are evil.
>
> I meant to add to my last post that even using lambdas this
> is a weird attempt at a factorial fiunction.
>
> Here's the equivalent from my web tutor on functional
> programming:
>
> >>> factorial = lambda n: ( (n <= 1) and 1) or
> ...                       (factorial(n-1) * n)
>
> >>> factorial(5)
> 120
>
> It uses the same basic constructs but much less esoteric trickery.
> Hopefully its slightly more readable,



Much more readable.

Anna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060310/7cf003c4/attachment.html 


More information about the Tutor mailing list