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

Why isn't my code getting rid of the 'o' in 'Words!'?

def anti_vowel(text):
    l = list(text)
    vowels = "aeiou"
    for letter in l:
        if letter.lower() in vowels:
    l = ''.join(l)
    return l


because you are removing from the same list as you iterating over, causing index shift, which causes problems for successive vowels.


Wouldn't that have created a problem on the two prior o's?


Yes, there the problem occurs. But then the o of lok is removed when the o of word is encountered, because remove() will remove the first instance it will find


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