The deadliest one-liner you’ve ever seen

Juan Luis Ruiz-Tagle
4 min readJul 28, 2022

A single python statement which will blow your mind

Image by author

Ok, now I have your attention. First of all, sorry for the clickbait-ish title, mainly because the one-liner you see above is not really doing something “useful”. Its output is more on the “artistic” side, the ASCII Art kind of thing.

If you run the code you will get this:

Image by Author

Yep, an ASCII Art circle. Nothing out of this world. I think it’s pretty awesome for a one-liner though.

How does it work?

The whole thing is based on the fact that you can define a lambda function and call it straight away. For example, this function (lambda x : x * 2)(3) multiplies its input by two and is called immediately after being defined. The input is 3, so it returns 6.

I have decomposed our deadly lambda function so that it is easier to read. It has two parameters, the radius r of the circle, and the length n of the grid side which will contain it. In the one-liner, I just define it and call it for r = 14 and n = 34.

--

--

Responses (1)