Anti_Vowel? Why doesn't this work?


Can someone explain to me why this code doesnt work? But when i add
but when i add

if x is not in letters:
word += x
return x

It chooses to work? Whats the main difference here.

def anti_vowel(text):
    letters = "aeiouAEIOU"
    word = ""
    for x in text:
        if (x != letters):
            word += x
    return x


This will probably never be true, it is comparing it to an entire list.


5 != [5, 6, 12, 21345]


Ahhh is there a better alternative i could have used rather than if x is not in letters?

For some reason i couldn't remember that method by myself, and the first thing i resorted to was !=


I would use (not much shorter):

x not in letters:

You don't need the is keyword in there. :slight_smile: