Anti_vowel problem


#1


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:
        lst.append(i)
        
    for index,letter in enumerate(lst):
        for character in test:
            if letter == character:
                del lst[index]
             
    string = "".join(lst)
    return string


#2

"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.


#3

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


#4

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


#5

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

return ''.join(final)

#6

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

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

please help....


#7

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)

#9