reduce(operator mulrange( - )to avoid lambda #!python from __future__ import print_function from functools import reduce from timeit import repeat import math def fact ( )if = return elsereturn fact ( - def fact ( )return if = else fact ( - def fact ( )return reduce(lambda xyx yrange( + )def fact ( )res for in range( + )res * return res def fact ( )return math factorial(nfile factorials py recursive fails at by default recursiveone-liner functional iterative stdlib "batteriestests print(fact ( )fact ( )fact ( )fact ( )fact ( ) * * * * * all print(fact ( =fact ( =fact ( =fact ( =fact ( )true for test in (fact fact fact fact fact )print(test __name__min(repeat(stmt=lambdatest( )number= repeat= )) "" :\codepy - factorials py true fact fact fact fact fact ""conclusionsrecursion is slowest on my python and machineand fails once reaches due to the default stack size setting in sysper this limit can be increasedbut simple loops or the standard library tool seem the best route here in any event this general finding holds true often for instance'join(reversed( )may be the preferred way to reverse stringeven though recursive solutions are possible appendix dsolutions to end-of-part exercises