Newbie question about for...in range() structure

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Fri Apr 18 04:25:16 EDT 2008


sp at k a écrit :
(snip - already answered)
> 
> def fact(n):
> 	total = 0
> 	n = int(n)
> 	while n > 0:
> 		total *= n
> 		n -=1
> 	return total

You may be interested in a very different way to get the same result:

from operator import mul

def fact(n):
    return reduce(mul, xrange(1, n+1), 1)


(snip)



More information about the Python-list mailing list