It is not just a matter of taste. Higher-level operations are more idiomatic.
For example, if I see a for-loop, all I know is we're doing some sort of a repeated operation. But when I see "map", I know we're doing a transformation on each item of a list, which is much more specific.
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.
63
u/thatlightningjack Jul 11 '26
What's
print([x*x for x in range(1,5)])?20
u/hhuzar Jul 11 '26
Since everything is constant: print("[1, 4, 9, 16]")
4
u/overclockedslinky Jul 11 '26
no need to reinvent the wheel!
pip install square1234
python -m square1234
3
u/Music_Quartermaster Jul 11 '26
7
u/deltadstroyer Jul 11 '26
i cant read that shit
gimme the longform
Pc dont care anyway
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
1
u/MathdallasRblx Jul 13 '26
List comprehension is bettah
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."
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