Question on Anti_vowel topic


so i have been doing the Anti_vowel topic and i did it eventually, but my code is a bit long winded, as you can see.
What i wanted to know is how to shorten down the if, elif stetement because it was horrible to writeall those each time.

def anti_vowel(text):
    word = []
      for letter in text:
        for i in word:
            if "a" in word:
            elif "A" in word:
            elif "e" in word:
            elif "E" in word:
            elif "i" in word:
            elif "I" in word:
            elif "o" in word:
            elif "O" in word:
            elif "u" in word:
            elif "U" in word:
    return "".join(word)

i tried including the lower and upper letters to cut down by half:
if "a" or "A" in word:
but this was giving me an error, it would have been nice but doesn't work.
i couldn't use the or/and within an in usage(who knows why?)
is there a shorter wayi can write this code for efficiency instead of all those elif's i have.

thank you in advance


Replace this line with your code.


if you wanted to do this you would get:

if "a" in word or "A" in word:

still not very efficient.

You should be able to use in, in a more effective way

For a simply string (like Hey You!) your program makes 24 loop iterations. This number will increase if the string becomes longer

i personally wouldn't even use .remove() to solve this problem, given the complication its gives (index shifts), which you can overcome like you did by looping over the string many times

go for the opposite approach, append constants to a new list/string (you pick/choice)


Hey stetim94
so i was going over the code and i found a quick way to do it, lot easier than my first.

def anti_vowel(text):
word = []
for letter in text:
if letter not in "aeiouAEIOU":
return "".join(word)

print anti_vowel("hello")
This prints hll

thanks for the assistance and guidence to make me look again.
much appreciated


that is a much better solution :slight_smile: Well done :slight_smile: