python - if not in list [duplicate]

假如想象 提交于 2019-12-04 22:35:37

How about this?

for item in mylist:
    if item in checklist:
        pass
    else:
       # do something
       print item

Your code should work, but you can also try:

    if not item in mylist :

if I got it right, you can try

for item in [x for x in checklist if x not in mylist]:
    print (item)
Jose Manuel

You better do this syntax

if not (item in mylist):  
    Code inside the if
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!