list comprehension with multiple conditions (python)
<p>The following code works in Python</p>

<pre><code>var=range(20)
var_even = [0 if x%2==0 else x for x in var]
print var,var_even
</code></pre>

<p>However, I thought that the conditions need to be put in the end of a list. If I make the code</p>

<pre><code>var_even = [0 if x%2==0 for x in var]
</code></pre>

<p>Then it won't work. Is there a reason for this?</p>