diff options
author | Guido van Rossum <guido@python.org> | 1994-09-23 14:08:41 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1994-09-23 14:08:41 (GMT) |
commit | c24da7cbbcd1a52720dd732f739c3e5b4724b2d1 (patch) | |
tree | 97c6416034c764e72e9272717171f3602aa9285e /Misc/FAQ | |
parent | be9f149574d681789cfb9da8d184e13e37eb5178 (diff) | |
download | cpython-c24da7cbbcd1a52720dd732f739c3e5b4724b2d1.zip cpython-c24da7cbbcd1a52720dd732f739c3e5b4724b2d1.tar.gz cpython-c24da7cbbcd1a52720dd732f739c3e5b4724b2d1.tar.bz2 |
Added obfuxcated lambda's by Ulf Bertelt
Diffstat (limited to 'Misc/FAQ')
-rw-r--r-- | Misc/FAQ | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -116,6 +116,7 @@ Here's an overview of the questions per chapter: ImportError: No module named ...; what gives? 4.11. Q. What GUI toolkits exist for Python? 4.12. Q. Are there any interfaces to commercial database in Python? + 4.13. Q. Is it possible to write obfuscated one-liners in Python? 5. Extending Python 5.1. Q. Can I create my own functions in C? @@ -683,6 +684,35 @@ A. There's an interface to SYBASE by John Redford There's also an interface to metalbase by Lance Ellinghouse <lance@markv.com>. +4.13. Q. Is it possible to write obfuscated one-liners in Python? + +A. Yes. See the following three examples, due to Ulf Bartelt: + +# Primes < 1000 +print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,\ +map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),range(2,1000))) + +# First 10 Fibonacci numbers +print map(lambda x,f=lambda x,f:(x<=1) or (f(x-1,f)+f(x-2,f)): f(x,f),\ +range(10)) + +# Mandelbrot set +print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,\ +Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,\ +Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,\ +i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y\ +>=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(\ +64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy\ +))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24) +# \___ ___/ \___ ___/ | | |__ lines on screen +# V V | |______ columns on screen +# | | |__________ maximum of "iterations" +# | |_________________ range on y axis +# |____________________________ range on x axis + +Don't try this at home, kids! + + 5. Extending Python =================== |