-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A suggestion on the mandelbrot one-liner in the docs FAQ #97709
Comments
As I suggested in issue at link python#97709
I think that it goes against the initial purpose of these examples: showing an obfuscated code with lambdas. The first example print(list(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))))) could be rewritten in shorter and clearer form which does not use explicit lambdas at all: print([y for y in range(2,1000) if all(y%x for x in range(2,int(y**0.5+1)))]) But then it would not be a good example for this question. |
Fair enough. Even then, I'm annoyed at the fact that the code doesn't explicitly insert newlines, is it possible to send another pull request, except changing only the part which concatenates lines? The code would be: print((lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+'\n'+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)) The results may be seen on the collab link: https://colab.research.google.com/drive/1RHtPuTYqwLiRh7S8SckI-cZj50fgvzGt#scrollTo=VJaN5YFEedqe |
Included newline separator in Mandelbrot set Now the Mandelbrot set one-liner example on separates the lines with a '\n' character.
…H-97737) Included newline separator in Mandelbrot set Now the Mandelbrot set one-liner example on separates the lines with a '\n' character. (cherry picked from commit 4980260) Co-authored-by: matheusja <[email protected]>
…H-97737) Included newline separator in Mandelbrot set Now the Mandelbrot set one-liner example on separates the lines with a '\n' character. (cherry picked from commit 4980260) Co-authored-by: matheusja <[email protected]>
thanks!
|
Included newline separator in Mandelbrot set Now the Mandelbrot set one-liner example on separates the lines with a '\n' character. (cherry picked from commit 4980260) Co-authored-by: matheusja <[email protected]>
…) (#97823) Included newline separator in Mandelbrot set Now the Mandelbrot set one-liner example on separates the lines with a '\n' character. (cherry picked from commit 4980260) Co-authored-by: matheusja <[email protected]>
Included newline separator in Mandelbrot set Now the Mandelbrot set one-liner example on separates the lines with a '\n' character. (cherry picked from commit 4980260) Co-authored-by: matheusja <[email protected]>
Documentation
On the docs FAQ there's a about obfuscated one-liners. The third one is a about the mandelbrot fractal, using the code:
I suggest 2 changes:
Replace
reduce(lambda x, y: x+y, <...>)
with''.join(<...>)
Make the outer join intersperse the lines with a newline character instead of relying on line wrapping. This will turn the outer
''.join(<...>)
into'\n'.join(<...>)
This results on the following code:
You can see the result and compare both on the following colab link: https://colab.research.google.com/drive/1NWfwNH_o5GPRTWwCdS-pVQLwEOSgstnz?usp=sharing
The text was updated successfully, but these errors were encountered: