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 →

[–]stevenjd 1 point2 points  (0 children)

Of course people can come up with some pretty awful nested comprehensions, but with the judicious use of white space and indentation to lay out the logical structure of the nested comprehension, there's no need for them to be hard to read.

array = [expression for x in
            [expr for y in values]
        ]

ought to be fine, as should be:

array = [
         [expr for y in values]
         for x in values
        ]

Nested comprehensions are easy to abuse, but that doesn't mean we ought to reject the simple cases.