Iteration for Factorials

Paul Rubin http
Wed Oct 24 21:36:15 EDT 2007


Lou Pecora <pecora at anvil.nrl.navy.mil> writes:
> There might even be an array method that can be adapted to get the 
> product.  Is there a product method? (analogous to a sum method)

The "reduce" function which is being removed from python in 3.0.

import operator
def factorial(n):
  return reduce(operator.mul, xrange(1,n+1))



More information about the Python-list mailing list