Why does anti_vowel fail in some cases?


abusing the operator or :wink:

def anti_vowel(text):
result = “”
for i in text:
if i == ‘A’ or i == ‘a’ or i == ‘E’ or i == ‘e’ or i == ‘o’ or i == ‘O’ or i == ‘U’ or i == ‘u’:
result += " "
result += i
return result

print anti_vowel(“Hello word”)


I wrote my code this way:

def anti_vowel(text):
  for char in text:
    if char not in "aeiouAEIOU":
      print char,

anti_vowel("dog eat dog") #prints out "d g   t   d g"

The result should be acceptable, since it does remove the vowel but the site doesn’t seem to like this solution. I wonder why? Is it because of the spaces between the printed characters?


also, and you only print the anti vowel string, you need to return it


I’m not quite sure why my code doesn’t work? It seems to remove all vowels except for the one “o” in “Hey look words!” I’m not necessarily looking for a solution, I just want to know why my code doesn’t work. Thanks for any help.

def anti_vowel(text):
lst =
final = “”
for c in text:
print lst
for c in lst:
if c in “aeiouAEIOU”:
print lst
for c in lst:
final += c
print final
return final


removing from the same list as you are looping over, is a bad idea

lists can’t have empty spots/slots, so the moment you remove something from the list, everything to the right of the removed item shifts one space to the left

combined with the loop you are using (which moves to the next index), this causes letters to be skipped