Iteration for Factorials

Marco Mariani marco at sferacarta.com
Tue Oct 23 06:55:04 EDT 2007


Tim Chase wrote:

>>>> fact = lambda i: i > 1 and reduce(mul, xrange(1, i+1)) or not
> i and 1 or None
> 
> Stunts like this would get a person fired around here if they
> were found in production code :)

eheh, indeed.


def fact(n):
     try:
         return eval('*'.join(str(x) for x in range(1,n+1)))
     except:
         return 1



More information about the Python-list mailing list