How on Factorial

Xavier Ho contact at xavierho.com
Thu Oct 28 06:19:14 EDT 2010


On 27 October 2010 18:27, Arnaud Delobelle <arnodel 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!
>

Huh, I've never seen that one before. Seems to work on both positive and
negative numbers. Is there a caveat to this?

Cheers,
Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101028/3ef78c3b/attachment-0001.html>


More information about the Python-list mailing list