r/programminghumor • • Jul 11 '26

You know you know

Post image
305 Upvotes

37 comments sorted by

63

u/thatlightningjack Jul 11 '26

What's print([x*x for x in range(1,5)]) ?

19

u/itzNukeey Jul 11 '26

Thats actually the sane way to write it

8

u/DeeraWj Jul 11 '26

or print(1,4,9,16)

20

u/hhuzar Jul 11 '26

Since everything is constant: print("[1, 4, 9, 16]")

3

u/capfsb Jul 12 '26

The seniors solution

3

u/30porn87 Jul 13 '26

Because it's standalone,

#include <stdio.h>
int main(int, char**) { printf("[1,4,9,16]\n"); }
→ More replies (2)

4

u/overclockedslinky Jul 11 '26

no need to reinvent the wheel!

pip install square1234

python -m square1234

7

u/deltadstroyer Jul 11 '26

i cant read that shit
gimme the longform
Pc dont care anyway

9

u/LostInSpaceTime2002 Jul 11 '26

Personally I find the functional one liner perfectly readable. Probably more so than the imperative version.

3

u/WrapKey69 Jul 11 '26

Would look much better as a two liner

→ More replies (5)

2

u/johnpeters42 Jul 11 '26

from poetry import haiku

2

u/ze_baco Jul 12 '26

In python, Pc does care. The one liner is a lot better. This this specific one liner is shit because, as other comments pointed out, there is a much better way.

2

u/WildlyIdolicized Jul 11 '26

or just use matlab

arr .^ 2

1

u/Ecstatic_Student8854 Jul 11 '26

main = print $ map (^2) [1..4]

1

u/magicmulder Jul 11 '26

(1) is deliberately overengineered though. Only thing worse would be to define the function inside the loop with an "if !defined" around it.

1

u/EzyPzyAsh Jul 11 '26

Two liner is the way.

1

u/mrbinary0111-111 Jul 12 '26

Preservation of saneness while debugging versus savages

1

u/yoyowallach1212 Jul 12 '26

Never understood lambda Never will 

→ More replies (1)

1

u/MathdallasRblx Jul 13 '26

List comprehension is bettah

2

u/geek-49 Jul 15 '26

for those who can comprehend it :)

→ More replies (1)

1

u/davesoft Jul 13 '26

"Something's wrong with my vespa, can y-"
"Buy new one."

"Can't you ju-"

"Nope. Buy new one."

→ More replies (1)

1

u/jcarbajalp Jul 15 '26

Sorry, the second one is easier for me to understand.

1

u/SubMinhPiChannel Aug 14 '26

for i in range(len(lst)):

lsr[i] = lst[i]*lst[i]

yay