Tuesday, January 1, 2008

Lambda Magic To Find Prime Numbers


Find prime number up to 100 with just 3 lines of code. The 4th line is for printing ;)


nums = range(2, 100)
for i in range(2, 10):
    nums = filter(lambda x: x == i or x % i, nums)
print nums


Isn't it amazing ?

No comments:

Post a Comment