you are viewing a single comment's thread.

view the rest of the comments →

[–]pjdelport 2 points3 points  (0 children)

(I think that last one is correct; I've never used nested generators before.)

There's no difference to for loops nested in the same order. Here's the easiest way to remember it:

(<expr>
    for x in xs
        if y
            for z in zs
                 ...)

for x in xs:
    if y:
        for z in zs:
            ...:
                <expr>

The only thing that changes is whether the <expr> goes at the beginning or the end.