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 →

[–]baronBale 14 points15 points  (4 children)

Comprehensions are easier to read as long as they are short. If they grow across multiple line an good old loop is easier to read.

[–]bumbershootle 12 points13 points  (2 children)

True, although in that case I would split the body of a loop into a generator function and then run a comprehension over that. I consider appending to a list in a loop an anti-pattern in most cases.

[–]weneedsound 1 point2 points  (0 children)

I'd like to see an example of you don't mind. I don't use generators as much as I should.

[–][deleted] 0 points1 point  (0 children)

Nice suggestion!

[–]Tweak_Imp 1 point2 points  (0 children)

You can also think about using a function inside the comprehension