Why does anti_vowel fail in some cases?


#21

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 += " "
else:
result += i
return result

print anti_vowel(“Hello word”)


#22

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?


#23

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


#24

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:
lst.append©
print lst
for c in lst:
if c in “aeiouAEIOU”:
lst.remove©
print lst
for c in lst:
final += c
print final
return final


#25

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