Unexpected error in Anti Vowel



def anti_vowel(text):
    for i in text:
        if i in "aeiouAEIOU":
                 text = text.replace(text[text.index(i)], "")
        print text
    return text
anti_vowel("Hey look Words!")


Above is my code and although it works fine it does not pass the compilers tests. Following is the error that the compiler throws:

Oops, try again. Your code looks a bit off--it threw a "substring not found" error. Check the Hint if you need help!

I would really appreciate your help. Stuck here since sometime now. Thanks in advance.


We already have i in hand so why not just pass i ?
Make sure your indentation is correct.

also the error is due the fact that you're looping over your main string and when it finds some vowel ,it replaces all of them with an empty string!! about the error ,It says substring not found ?
means there is no character so you have error rather than index of it.

One more thing..
Instead looping over text and replacing the vowels with "", we can't direct loop over "aeiouAEIOU" ?


hey greentreeme,
Iam not quite sure what you mean by "it replaces all of them with an empty string!! ", I have attached a photo, in o/p console I do achieve the intended result. Also if you'd be so kind to explain how looping over "aeiouAEIOU" works.


take an example..

x = "I'm green."
x = x.replace("e","")

print x #prints "I'm grn."

You can see replace replaced all "e"'s with empty string ""


yes that's correct but isn't that what is intended?


Also above was done to find the index of i, is that not the correct method?


what're you doing is to put the value then find the index using .index() method then put the index using [] operator to find the value again? (This makes us to get dependent on main string text)
rather this we can use i? as i is already that character(vowel)


doesn't replace work only with index?


In the example above, I have not used index() method or index but item?


Yes thank you so much greentreeme! I made the change of passing i itself and it worked fine. thank you for being so patient with me. I am usually not so ditzy. Again your help is greatly appreciated, so is your patience.


It's all good ! :slight_smile:
try this tool to visualize your first code, You will know what actually happening at each step and why the first method did not worked out!


thank you, the tool is very convenient.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.