Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


The term nested list comprehension is used differently here: 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.


Good point. I fixed it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: