Fun with lambda and map

Frederick H. Bartlett fbartlet at optonline.net
Tue Jan 29 09:16:13 EST 2002


I see. And Python's great advantage is that it's so much easier to
understand than Perl.

gerson.kurz at t-online.de (Gerson Kurz) wrote in message news:<3c566a21.22129828 at news.t-online.de>...
> primes = lambda o:map(lambda a:filter(None,(map(lambda i:map(lambda
> x:a.__setitem__(x,0),range(2*i,o,i)),range(2,o)),a)[1])[1:],[range(o)])[0]
> 
> print primes(20)
> 
> fibonacci = lambda x:map(lambda o:(map(lambda c:map(lambda
> l:o.__setslice__(l[0],l[1],l[2]),([o[2]+3,o[2]+4,[o[0]]],[0,3,[o[1],reduce(lambda
> x,o:x+o,o[:2]),o[2]+1]])),range(x)),o)[1],[[1,1,0]+range(x)])[0][3:]
> 
> print fibonacci(20)
> 
> (Note: These probably need python 2.2 to work because of the lambda
> scope thing)



More information about the Python-list mailing list