Iteration for Factorials

tokland at gmail.com tokland at gmail.com
Mon Oct 22 16:10:10 EDT 2007


On 22 oct, 20:35, Paul Rudin <paul.nos... at rudin.co.uk> wrote:

> import operator
> def fact(x):
>     return reduce(operator.mul, xrange(1,x))

Maybe:

import operator
def fact(x):
    return reduce(operator.mul, xrange(2, x+1), 1)

fact(0)
1
fact(4)
24




More information about the Python-list mailing list