Calculating factorial

Steve Horne sh at ttsoftware.co.uk
Tue Dec 5 12:43:51 CET 2000


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

>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 lurking.demon.co.uk
Work : sh at ttsoftware.co.uk



More information about the Python-list mailing list