News for hackers. Stuff that matters.
Re:One-lined Python by sp332 on Wednesday August 21, 2019 @10:25AM (#20757473)
The demo at the top doesn't work because it's expecting python 3 but the demo code is python 2.
Re:One-lined Python by trymas on Thursday August 22, 2019 @05:50AM (#20766296)
Even if fixed to python 3, still throws an error:

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

Re:One-lined Python by np_tedious on Thursday August 22, 2019 @06:15AM (#20766434)
Python3 put it in functools, I think. Ah the need for an import would prevent one lining.

Never quite understood that decision

Re:One-lined Python by gvx on Thursday August 22, 2019 @06:29AM (#20766502)
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__

    __import__('functools').reduce
Re:One-lined Python by jmmcd on Thursday August 22, 2019 @09:05AM (#20767560)
The article goes on to use `__import__()` to one-line imports.
Re:One-lined Python by olooney on Thursday August 22, 2019 @10:56AM (#20768772)
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.
Re:One-lined Python by xamuel on Thursday August 22, 2019 @12:01PM (#20769532)
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

Re:One-lined Python by sethgecko on Thursday August 22, 2019 @11:08AM (#20768920)
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
Re:One-lined Python by kiddico on Thursday August 22, 2019 @11:30AM (#20769179)
Followed by watching the rest of his videos! Each one is gold.
Re:One-lined Python by virusduck on Thursday August 22, 2019 @10:54AM (#20768752)
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.
Re:One-lined Python by gustavorg on Thursday August 22, 2019 @12:00PM (#20769523)
Re:One-lined Python by virusduck on Thursday August 22, 2019 @12:14PM (#20769644)
I believe it is 切腹, but ok.
Re:One-lined Python by pixelbath on Thursday August 22, 2019 @06:25PM (#20772955)
"Seppuku" is the accepted romanization of 切腹; why does it seem incorrect to you?
Re:One-lined Python by obenn on Thursday August 22, 2019 @07:06AM (#20766709)
Neat, I just learned what the Y combinator actually is!
Re:One-lined Python by pohl on Thursday August 22, 2019 @01:25PM (#20770399)
No newlines allowed. No semicolons, either.

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

Re:One-lined Python by RocketSyntax on Thursday August 22, 2019 @05:30PM (#20772564)
great for submitting complex one liners via docker exec