How on Factorial

Wolfram Hinderer wolfram.hinderer at googlemail.com
Sat Oct 30 08:27:18 EDT 2010


On 27 Okt., 10:27, Arnaud Delobelle <arno... at gmail.com> wrote:
> True.  It's far too verbose.  I'd go for something like:
>
>     f=lambda n:n<=0 or n*f(~-n)
>
> I've saved a few precious keystrokes and used the very handy ~- idiom!

You can replace "n<=0" with "n<1". Then you can leave out the space
before "or" ("0or" wouldn't work with newer python versions).

f=lambda n:n<1or n*f(~-n)

Much better, isn't it? ;-)



More information about the Python-list mailing list