Using if for multiple input lists in Python list comprehension
<p>How do you use an if statement in a list comprehension when there are multiple input lists.  Here is the code that I'm using and the error that I'm getting: </p>

<p>(I get that it's not able to apply modulus to a list, but not sure how to specifically reference the x in each of the lists as it iterates through them)</p>

<pre><code>a = [1,2,3]
b = [4,5,6]

nums = [x**2 for x in (a,b) if x%2==0]
print(nums)

TypeError: unsupported operand type(s) for %: 'list' and 'int'
</code></pre>

<p>As Jim said, you are <code>mod</code> a list to a <code>int</code>.</p>

<p>You can also use <code>+</code>, e.g., <code>nums = [x**2 for x in a+b if x%2==0]</code>.</p>

python python-3.x list-comprehension