Tuesday, October 19, 2010

Fun with Python

This is really pretty useless... but a great example of something awesome you can do with 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.

No comments: