Fun with lambda and map
gbreed at cix.compulink.co.uk
gbreed at cix.compulink.co.uk
Mon Feb 4 12:51:55 EST 2002
Gerson Kurz wrote:
> If you're in a masochistic mood, you can write this in one line:
>
> fac = lambda n:map(lambda x:(map(lambda a:a and 1,[x[0]()])[0] and
> x[1]()) or x[2](x[3]),[[lambda:not n,lambda:n==n,lambda
> n:fac(n-1)*n,n]])[0]
If you're allowing booleans and subtraction, how about
fac = lambda x: not x or x*fac(x-1)
?
Graham
(<http://www.microtonal.co.uk/>)
More information about the Python-list
mailing list