News for hackers. Stuff that matters.
Re:Strange line of Python by masklinn on Friday November 18, 2011 @07:29AM (#3251511)
This code yes, in TFA's code the inner iteration (on `states`) depends on the result of the outer iteration (on `state`).

For what it's worth, it's pretty easy to "unwrap" a Python listcomp: it's a sequence of nested loops, nested tests and a mapping.

    result = [mapping for iteration1 for iteration2 for iteration3 if test1 if test1]
is equivalent (modulo some scoping interaction with the code outside it) to

    result = []
    for iteration1
        for iteration2
            for iteration3
                if test1
                    if test2
                        result.push(mapping)
Apart from the final mapping, listcomps are executed strictly left to right, an evaluation can use anything produced to the "left" of it.

There are no comments on this comment yet.