On 10/02/11 11:23 AM, Vinod Parthasarathy wrote:
> Here's one way of writing factorial in Haskell.
>
> factorial 0=1
> factorial n=n*factorial(n-1)
And here's the pythonic way:
factorial = lambda n: n and n*factorial(n-1) or 1
Succinct :-)
Or even better:
from math import factorial # Batteries included!
print factorial(6)
The Haskell version is also neat (more readable IMO).
Cheers,
Chandrashekar.
--
http://www.chandrashekar.info/
http://www.slashprog.com/
PS: The above pythonic code doesn't work for negative numbers.
_______________________________________________
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc