How can I create a list where if a[0] or a[1] of a row of list a are not present in any rows of list b that row in list a is appended to list c?
<p>I have a list of lists <code>a</code> eg:</p>

<pre><code>a = [[1, 3, 7], [3, 5, 7], [-23, -34, -45]]
</code></pre>

<p>and another list <code>b</code> eg:</p>

<pre><code>b = [1, 2, 3, 4]
</code></pre>

<p>I want to create a list <code>c</code> where when the items in the first two columns of a single row of list <code>a</code> are not present in list <code>b</code> that row of a is appended to list c. In the example lists c would look like:</p>

<pre><code>c = [[7], [7], [-45]]
</code></pre>

<p>as the first row of <code>a</code> contains 1 and 3, both of which are present in <code>b</code> and the 2nd row contains 3 which is present in <code>b</code>.</p>

<p>I have tried the following without success:</p>

<pre><code>for row in a:
    if row[0] or row[1] not in b:
        c.append(a)
</code></pre>

<p>and</p>

<pre><code>for row in a:
    if row[1] not in b:
        if row[0] not in b:
            c.append(a)
</code></pre>

<p>as both just seem to copy <code>a</code> into <code>b</code></p>

<p>Does anyone know why my code isn't working/code that would instead?</p>

<p>edit: apologies, I got my expected result wrong the first time round</p>

<p>edit 2: I messed up big time - I was designing it all wrong, my input lists are coming from another source and I had copied them down wrong. So what I am actually looking to do is as follows</p>

<pre><code>c = [ ]

a = [[1, 3, -23], [3, 5, -34], [7, 7, -45]]
b = [1, 2, 3, 4]

for row in a:
    if row[0] not in b and row[1] not in b:
        c.append(row)
</code></pre>

<p>Thanks for everyone who helped. sorry I'm such an idiot.</p>
