"Hy lk Words!" - extra 'o'?



My code removes all of the vowels except one of the 'o's at the end even though it has removed all the other 'o's in the rest of the text. This is my error message - Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!".

I can't work out why it won't remove the 'o' in 'Words'

vowels = ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U')

def anti_vowel(text):
    text = list(text)
    for c in text:
        for v in vowels:
            if c == v:
    text = ''.join(text)
    return text


because of index shifts, you remove from the list you are looping over, this means if there are two consecutive vowels, like in look, the second vowel gets skipped.


But the extra vowel is in Words which doesn't have consecutive vowels.


so the second o in look gets skipped, but then the loop arrives at the o of words, but remove() will remove the first o it can find, which is the one your for loop skipped in look

If you don't know the behavior of the built in functions you are using, it can indeed let you to believe the problem is somewhere else then you think.

Remove is a difficult approach to solve this problem


Makes sense - thank you!


Do you think you can work out a solution, or do you need more help?


I have the same problem here, and could you give some advice to the solution?


There are multiply solutions possible, remove() is possible but not recommend, it is quit a difficult approach.

make an empty list, loop over text and append everything that is not a vowel to your list. After the loop, join the list into a string using .join()

If you need more help, make a new topic


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