python - 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? -


i have list of lists a eg:

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

and list b eg:

b = [1, 2, 3, 4] 

i want create list c when items in first 2 columns of single row of list a not present in list b row of appended list c. in example lists c like:

c = [[7], [7], [-45]] 

as first row of a contains 1 , 3, both of present in b , 2nd row contains 3 present in b.

i have tried following without success:

for row in a:     if row[0] or row[1] not in b:         c.append(a) 

and

for row in a:     if row[1] not in b:         if row[0] not in b:             c.append(a) 

as both seem copy a b

does know why code isn't working/code instead?

edit: apologies, got expected result wrong first time round

edit 2: messed big time - designing wrong, input lists coming source , had copied them down wrong. looking follows

c = [ ]  = [[1, 3, -23], [3, 5, -34], [7, 7, -45]] b = [1, 2, 3, 4]  row in a:     if row[0] not in b , row[1] not in b:         c.append(row) 

thanks helped. sorry i'm such idiot.

slight modification on @muzulget's answer:

for row in a:     if row[0] not in b or row[1] not in b:         c.append(a[2]) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -