Search code examples
pythonpython-3.xlogic

Is there a way to write two "in" statements in one?


Is there a short version of

n = [5, 3, 17]
if 5 in n and 17 in n:
    print("YES")

something like that doesn't seem to work

if (5 and 17) in n:
   print("YES")

Any suggestions?


Solution

  • You could use something like this instead:

    n = [5,3,7]
    
    if all(item in n for item in [5,7]):
        print("YES")