def factorial(n):

n = abs(int(n))

n = 1 if not n else n

return reduce(lambda x,y: x*y, xrange(1, n+1))

It's a waste of time when the math module already contains math.factorial, but it just shows off some of the more esoteric features of Python.

skip to main |
skip to sidebar
## Tuesday, October 19, 2010

###
Fun with Python

Life, Tech, Love, and Whatever Tickles My Fancy

This is really pretty useless... but a great example of something awesome you can do with Python:

It's a waste of time when the math module already contains math.factorial, but it just shows off some of the more esoteric features of Python.

def factorial(n):

n = abs(int(n))

n = 1 if not n else n

return reduce(lambda x,y: x*y, xrange(1, n+1))

It's a waste of time when the math module already contains math.factorial, but it just shows off some of the more esoteric features of Python.

Subscribe to:
Post Comments (Atom)

## No comments:

Post a Comment