4 ms·
It's a list comprehension with an implicit nested loop: >>> [y for z in [[1,2,3],[4,5,6]] for y in z] [1, 2, 3, 4, 5, 6] The error you get is because
by lisper 11y ago
It's a list comprehension with an implicit nested loop:
>>> [y for z in [[1,2,3],[4,5,6]] for y in z]
[1, 2, 3, 4, 5, 6]
The error you get is because "planet" is bound by the second FOR clause, so when you leave it out, planet becomes unbound.
- andreasvc 11y agoThe term nested list comprehension is used differently here: https://docs.python.org/3/tutorial/datastructures.html#nested-list-comprehensions https://docs.python.org/3/tutorial/datastructures.html#neste... Don't know what a better term might be, but it's good to be aware of the distinction.
- lisper 11y agoGood point. I fixed it.