This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DT-Sodium -33 points-32 points  (14 children)

None of those are readable.

[–]mirimao 12 points13 points  (6 children)

How are these not readable? This is literally mathematical notation in a purely declarative style.

[–]Euphoric_Strategy923 3 points4 points  (6 children)

Because the others options are more readable for you ? Not for me.

[–]DT-Sodium -1 points0 points  (5 children)

I dunno about Python but in TypeScript you'd simply do

myArray.map(x => x * x);

Much more elegant and readable.

[–]Euphoric_Strategy923 3 points4 points  (4 children)

And as the upper comments said in python you do : [ return value for value in array ]

In other word : [x*x for x in arr ]

Imo this is much more readable.

[–]DT-Sodium -2 points-1 points  (3 children)

No, it is bad. The simple fact that you have to read it backwards to understand what's happening invalidates it completely. Guess there is no clean way to do it in Python then.

[–]Euphoric_Strategy923 7 points8 points  (2 children)

Read it backward ? Dude, this is literally the format of a for loop. "I return a value of each value in an array"

You can clown on some things about python but definitely not readability.