python 3.x - Why does my list inclusion negation not work? -


as part of (python 3.3) program writing, comparing 2 lists; want find every member of second list not occur in first list can build database command. "in" membership test works expect, negation not.

for instance:

l1 = ['mne11b', 'dlc05a', 'mkh08a', 'pergdm', 'dlw12b', 'fsw08a', 'pnc12a', 'khh04a', 'bwd12a', 'ydb12a'] l2 = ['mkh08a', 'fsw08a', 'bwd12a']  print("present") x in l2:     if x in l1:         print(x)  print("not present") x in l2:     if x not in l1:         print(x) 

the first "for" loop prints out 3 members in l2 exist in l1. expect second loop print out members in l2 not in l1; instead prints nothing @ all. why this? have tried various syntactical tricks parentheses , such, being stubborn.

every item in l2 in l1, if x not in l1 evaluate false.

>>> l1 = ['mne11b', 'dlc05a', 'mkh08a', 'pergdm', 'dlw12b', 'fsw08a', 'pnc12a', 'khh04a', 'bwd12a', 'ydb12a'] >>> l2 = ['mkh08a', 'fsw08a', 'bwd12a'] >>> x in l2:     if x not in l1:         print(x)   >>> l2.append('xyz31t') >>> x in l2:     if x not in l1:         print(x)  xyz31t 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -