
One-lined Python - Symmetry
http://www.onelinerizer.com
======
sp332
The demo at the top doesn't work because it's expecting python 3 but the demo
code is python 2.

~~~
trymas
Even if fixed to python 3, still throws an error:

> Your code could not be one-lined. name 'reduce' is not defined

~~~
np_tedious
Python3 put it in functools, I think. Ah the need for an import would prevent
one lining.

Never quite understood that decision

~~~
gvx
Reduce isn't used much. Things that tend to use reduce in languages like
Haskell tend to be built from other primitives in Python.

Instead of reduce, you could use
[https://docs.python.org/3/library/functions.html#__import__](https://docs.python.org/3/library/functions.html#__import__)

    
    
        __import__('functools').reduce

------
olooney
I like this. Here is a one-liner I wrote recently that calculates the 10th
Fibonacci number:

    
    
        (lambda n: n(lambda x: x+1)(0))(((lambda f: (lambda x: x(x))(lambda y: f(lambda z: y(y)(z))))(lambda f: (lambda f: lambda n: (lambda f: lambda x: x) if (lambda b: b(True)(False))((lambda n: n(lambda x: (lambda x: lambda y: y))(lambda x: lambda y: x))(n)) else f(n))(lambda n:(lambda m: lambda n: (lambda m: lambda n: (lambda n: n(lambda x: (lambda x: lambda y: y))(lambda x: lambda y: x))((lambda m: lambda n: n((lambda n: lambda f: lambda x: n(lambda g: lambda h: h(g(f)))(lambda u: x)(lambda u: u)))(m))(m)(n)))((lambda n: lambda f: lambda x: f(n(f)(x)))(m))(n))(n)((lambda n: lambda f: lambda x: f(n(f)(x)))(lambda f: lambda x: f(x)))(n)((lambda m: lambda n: lambda f: lambda x: m(f)(n(f)(x)))(f((lambda m: lambda n: n((lambda n: lambda f: lambda x: n(lambda g: lambda h: h(g(f)))(lambda u: x)(lambda u: u)))(m))(n)(lambda f: lambda x: f(x))))(f((lambda m: lambda n: n((lambda n: lambda f: lambda x: n(lambda g: lambda h: h(g(f)))(lambda u: x)(lambda u: u)))(m))(n)((lambda n: lambda f: lambda x: f(n(f)(x)))(lambda f: lambda x: f(x)))))))))(lambda f: lambda x: f(f(f(f(f(f(f(f(f(f(x))))))))))))
    

Paste that into a Python 3 interpreter, you should see "55". Somewhere in
there is the Y-contaminator and several other tricks similar to what this
article describes.

~~~
xamuel
If you like that sort of thing, try doing similar code for the Ackermann
function [1]. In a certain sense that can be made semi-formal, if you can do
this sort of thing for the Ackermann function, then you can do it for almost
anything.

[https://en.wikipedia.org/wiki/Ackermann_function](https://en.wikipedia.org/wiki/Ackermann_function)

------
sethgecko
If you want your mind to blow up I recommend watching this year's "Lambda
Calculus from the Ground Up" PyCon talk by the wizard David Beazley
[https://www.youtube.com/watch?v=pkCLMl0e_0k](https://www.youtube.com/watch?v=pkCLMl0e_0k)

~~~
kiddico
Followed by watching the rest of his videos! Each one is gold.

------
virusduck
I want this to work so badly. Sadly, I think the Python on the website is
committing seppaku rather than being forced to abuse its brethren.

~~~
gustavorg
I believe is Seppuku
([https://en.wikipedia.org/wiki/Seppuku](https://en.wikipedia.org/wiki/Seppuku))

~~~
virusduck
I believe it is 切腹, but ok.

~~~
pixelbath
"Seppuku" is the accepted romanization of 切腹; why does it seem incorrect to
you?

------
obenn
Neat, I just learned what the Y combinator actually is!

------
pohl
_No newlines allowed. No semicolons, either._

In my head I read this in the voice of Harry Dean Stanton (Repo Man).

------
RocketSyntax
great for submitting complex one liners via docker exec

