So I would use:

reduce(int.__mul__, xrange(2, k+1), 1)

I actually are using:

from operator import mul

fact = lambda k: reduce( mul, range( 2, k + 1 ), 1 )

fact( 61 )

>>> reduce(int.__mul__, xrange(1, k+1), 1)

someone can accomplish even (slightly) better performance code as far as looping and memory efficiency is concerned (see help(xrange) for details).

Another “fix” would be to use the mul function from the operator module (import operator) so as not to have problems with the factorial of “big numbers”:

>>>import operator

>>> reduce(operator.mul, xrange(1, k+1))

Here are some measures trying to compute 60! using timeit module:

In [74]: timeit.Timer(‘reduce(lambda i,j: i*j, range(1, 61))’).timeit(number=100000)

Out[74]: 2.4469389915466309

In [75]: timeit.Timer(‘reduce(lambda i,j: i*j, xrange(1, 61))’).timeit(number=100000)

Out[75]: 2.3416600227355957

In [76]: timeit.Timer(‘import operator; reduce(operator.mul, xrange(1, 61))’).timeit(number=100000)

Out[76]: 1.5750751495361328

The correct function is ….

>>>reduce(int.__mul__, range(1, k+1),1)

]]>reduce(lambda i,j: i*j, range(1,k+1),1)

]]>