Simplifying != if statements

Question:

I’m scratching my head trying to find a more compact version of this if statement,

if a != b and a != c:
    foo()

Where all conditions are not boolean.
I could imagine that it would be tedious to write if there were more than 2 conditions to check for.

I also tried:

if a != (b and c):
    foo()

But (b and c) depend on their corresponding bool values rather than comparing equivalence to a.
Thanks in advance for any help!

Asked By: adamius

||

Answers:

I usually use

if a not in [b, c]:
    foo()
Answered By: vlizana
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.