News for hackers. Stuff that matters.
Re:Strange line of Python by Herald_MJ on Friday November 18, 2011 @07:21AM (#3251492)
So the code can be simplified as

>>> states * len(state)

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.
Re:Strange line of Python by llambda on Friday November 18, 2011 @07:25AM (#3251499)
Just the example. But this example is just to illustrate what's going on. It's not the same as what the author is trying to achieve.