This question describes how to use list comprehensions to flatten a nested structure, like so:
[leaf for tree in forest for leaf in tree]
As John Mee mentions in the comments, this would be clearer if the order of the for
statements was reversed, like so:
[leaf for leaf in tree for tree in forest]
Why are for loops in Python's list comprehensions interpreted in this order?