Anti_vowel: checking equivalence to multiple values at once


Link to Exercise: 15.8 anti_vowel

Hey champs. Does anyone know if it's possible to check if a condition is equal to not just one argument, but a bunch of different arguments all at once? e.g. if x == (a or b or c): instead of if x == a or x == b or x == c:

In the anti_vowel exercise, I know that I can just check if the element of the string is in another string, "aeiou." (See below)

def anti_vowel(text):
    voweless = ""
    for i in range(len(text)):
        if text[i].lower() not in "aeiou": #THE LINE IN QUESTION
            voweless += text[i]
    return voweless

I'm wondering if, instead of:

        if text[i].lower() not in "aeiou":

I could do something like:

        if text[i].lower() != ("a" or "e" or "i" or "o" or "u")

Thanks everyone!


Short answer... No. All three operands need to be complete expressions.

a or b or c

is a boolean expression that only returns True or False, regardless what the values of a, b, and c are.

0 or 0 or 0       => False
1 or 0 or 0       => True

'' or '' or ''    => False
'a' or '' or ''   => True


Thank you! That makes sense.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.