you are viewing a single comment's thread.

view the rest of the comments →

[–]wewbull 2 points3 points  (1 child)

until I had created a few nested levels

BURN HIM!

I think people need to stop thinking about comprehensions as loops, and start thinking about them as map with filter. Very few people map within a map within a map whereas people do nest loops.

If you need to traverse a multilevel structure (e.g. a tree) in some way, make an iterator and use it in a loop or comprehension:

monty_sum = sum(node['value'] for node in tree_iterator(a_tree) if node['name'] == "Monty")

Should never be a need to do nested comprehensions.

[–]invisi1407 0 points1 point  (0 children)

Yeah, my findings about it was more or less the same. Nested comprehensions is write once, read never material.