8.15 Anti-Vowel should work, but doesn't


#1

I'm lost. I don't know if I've made an error I haven't caught, but I can't figure out what makes this program just skip over "o" near the end. When I use the text "aeiou" it skips over both e and o. Can anyone look this over and help?


def anti_vowel(text):
new = []
for letter in text:
new.append(letter)
print new
for letter in new:
if letter == "a":
new.remove("a")
#
elif letter == "e":
new.remove("e")
#
elif letter == "i":
new.remove("i")
#
elif letter == "o":
new.remove("o")
#
elif letter == "u":
new.remove("u")
#
elif letter == "A":
new.remove("A")
#
elif letter == "E":
new.remove("E")
#
elif letter == "I":
new.remove("I")
#
elif letter == "O":
new.remove("O")
#
elif letter == "U":
new.remove("U")
#
result = ""
for letter in new:
result += letter

return result

print anti_vowel("aeiou")

I apologize, but I don't know how to include the indenting


#2

since you are performing this operation of going through the text and adding the characters to your new list.Why don't you only add the character you want to your new list instead of everything
Because removing elements from a list you are iterating is bad


#3

Don't know why I didn't see that before, but yeah, that's pretty redundant. When I tried your method, everything worked, so thank you. Is there a reason why my earlier function couldn't work?


#4

My example:


#5

Wow, that's pretty compact. Does the "if txt in "aeiouAEIOU"" mean if the text is found in "aeiouAEIOU"?


#6

Then you use FOR it looks like:
a
e
i
o
...
and I use IF for compare.