I have two list comprehensions where conditions are defined in different places.
>>> [ x**2 if x%2==0 else x**3 if x%3==0 else 0 for x in range(10)]
[0, 0, 4, 27, 16, 0, 36, 0, 64, 729]
>>> [ x**2 if x%2==0 for x in range(10) ]
File "<stdin>", line 1
[ x**2 if x%2==0 for x in range(10) ]
^
SyntaxError: invalid syntax
However if i do this:
>>> [ x**2 for x in range(10) if x%2==0 ]
[0, 4, 16, 36, 64]
>>>
it works.
Now the confusing part is how the order is evaluated. What is the difference?