Calculating factorial

Steve Horne sh at
Tue Dec 5 12:43:51 CET 2000

On Mon, 4 Dec 2000 17:45:46 +0100, "Alex Martelli" <aleaxit at>

>Attempts to get more sophisticated, such as
>def factorial(f):
>    import operator
>    return reduce(operator.mul, range(1,f+1), 1L)
>will not necessarily bring happiness.

Might be faster with xrange (which doesn't build the whole list before
returning), but the simple for loop will probably still win for speed.
Functional-style list manipulations (once you are used to them) are
for speed of development, not speed of execution.

Steve Horne
Home : steve at
Work : sh at

More information about the Python-list mailing list