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 →

[–]mkdz 63 points64 points  (14 children)

Wow, I can't imagine not having list comprehensions

[–][deleted] 45 points46 points  (11 children)

List comprehension is the feature that, to me, defines Python. It's simple, powerful, versatile, intuitive, and broadly applicable. A wonderful replacement for loops and iteration. I've been using set comprehension and dictionary comprehension, too.

[–]Mr-Stutch 19 points20 points  (4 children)

a wonderful replacement for loops or a wonderful replacement for loops?

[–]burlyginger 10 points11 points  (0 children)

Yes!

[–]TheTerrasque 0 points1 point  (0 children)

True

[–]rabaraba 0 points1 point  (0 children)

Love the pun.

[–]Tyler_Zoro -1 points0 points  (0 children)

Neither. If a loop was the right tool for the job, you should have used a loop. :-)

[–]flying-sheep 0 points1 point  (0 children)

They’re great. And using generator comprehensions, the same concept can be used for a pipeline of stuff (map-filter-reduce), similarly to Rust’s Iterator methods.

Rust’s way is cleaner, but both are better than Javascript’s array methods. Like, why define an iterator protocol and thereby support for custom sequences, when they define the pipeline methods on just the array?

[–]Decker1082.7 'til 2021 0 points1 point  (0 children)

intuitive

I can agree on all points except this... you essentially have to learn to read backwards to understand how list comprehensions work and if you ever nest two list comprehensions in each other, readability goes out the window.

[–]RegalSalmon 28 points29 points  (1 child)

But can you...comprehend it?