How on Factorial

Dave Angel davea at
Thu Oct 28 15:52:55 CEST 2010

On 2:59 PM, Xavier Ho wrote:
> On 27 October 2010 18:27, Arnaud Delobelle<arnodel at>  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
The ~- trick only works on two's complement numbers.  I've worked on 
machines in the past that used one's complement, and this wouldn't work 


More information about the Python-list mailing list