Anti_vowel


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096


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.remove(letter)
    l = ''.join(l)
    return l


#2

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


#3

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


#4

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


#5

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