Iteration for Factorials

Paul Rudin paul.nospam at rudin.co.uk
Mon Oct 22 16:38:05 EDT 2007


tokland at gmail.com writes:

> 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)

Or just:

reduce(operator.mul, xrange(1, x), 1)






More information about the Python-list mailing list