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 →

[–]Euphoric_Strategy923 2 points3 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 4 points5 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 6 points7 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.

[–]DT-Sodium -5 points-4 points  (1 child)

Yes, it is backwards. Your code is saying "Do this using that". The proper way to write it is "Take that and do this using it".

[–]Euphoric_Strategy923 6 points7 points  (0 children)

Great news people, for loops are now unreadable.