Anti_vowel problem


Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lok Wrds!" when it should return "Hy lk Wrds!".

Why is this happening?

def anti_vowel(text):
    test = "aeiouAEIOU"
    lst = []
    for i in text:
    for index,letter in enumerate(lst):
        for character in test:
            if letter == character:
                del lst[index]
    string = "".join(lst)
    return string


"Hey look words!"

When index is 1, the e is matched and the code above deletes that element from the list. Now it looks like this, (imagine in list form)

Hy look words!

index goes up to 4 and deletes the o that is matched. Now it looks like this,

Hy lok words!

When the index is 5, it sees a k, not the second o, which is slotted into the index-4 position.

So deleting looks less like a viable approach, here. Consider building a temporary list and only append non-vowels to it.


Thank you so much! So obvious yet deceiving :stuck_out_tongue:


def anti_vowel(text):
for i in text:
if i in "AaEeIiOoUu":
text = text.replace(i,"")
return text

much shorter, checks if each letter in text is a vowel. if it is the letter is replaced with nothing. ope this helps


def anti_vowel(text):
word_list = []
final = []
for i in range(len(text)):
for item in (word_list):
for c in 'AEIOUaeiou':
if item == c:

return ''.join(final)


def anti_vowel(text):
vowel = [ "a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
atxt = ""
word = ""
for i in range(len(text)):
for i in word:
for j in vowel:
if word[i] == vowel[j]:
return ''.join(atxt)

Oops, try again. Your code looks a bit off--it threw a "'str' object has no attribute 'append'" error

please help....


Thanks so much! This solved my problem:

def anti_vowel(text):    
    vowel = "aeiouAEIOU"
    word = ""
    for i in text:
        if i not in vowel:
            word += i
    return word

w = raw_input("Type a word: ")
print anti_vowel(w)