anti_vowel problems with conditional


#1

I don't quite understand why this doesn't work:

	if ((char.upper() != "A") or (char.upper() != "E") or (char.upper() != "I") or (char.upper() != "O") or (char.upper() != "U")):
		aVowel.append(char)

Python does not appear to be evaluating this conditional as I would expect it to. Any insight would be appreciated.


#2

I personally would just simplify that a tad bit,

def anti_vowel(input_):
    return ''.join((letter for letter in input_.lower() if letter not in 'aeiou'))

or

from re import sub
def anti_vowel(input_):
    return sub(r'[AEIOUaeiou]', '', input_)

or

def anti_vowel(input_):
    temp = []
    for letter in input_:
        temp.append(letter) if letter.lower() not in 'aeiou' else ''
    return ''.join(temp)

#3

Thanks, I like the regular expression solution. I figured my code out:

if false or false or false or true or false: will evaluate as false

To make it work it needs to use the and operator to evaluate correctly.

if ((char.upper() != "A") and (char.upper() != "E") and (char.upper() != "I") and (char.upper() != "O") and (char.upper() != "U")):
aVowel.append(char)