Works Until It Doesn't (Anti-Vowel)


#1

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


This is the error I'm getting.
"Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!""

I don't understand why it's working up until the last vowel...
I have looked through all the other vowel posts I could find. The most baffling thing is that of all the vowels it's messing up on, it's one that it executes correctly twice in a row. I literally have no idea what is wrong.

def anti_vowel(text):
    x = []
    for char in text:
        x.append(char)
    for char in x:
        if char == "A":
            x.remove(char)
        elif char == "a":
            x.remove(char)
        elif char == "E":
            x.remove(char)
        elif char == "e":
            x.remove(char)
        elif char == "I":
            x.remove(char)
        elif char == 'i':
            x.remove(char)
        elif char == 'O':
            x.remove(char)
        elif char == 'o':
            x.remove(char)
        elif char == 'U':
            x.remove(char)
        elif char == 'u':
            x.remove(char)
    text = "".join(x)
    return text


#2

remove() is a difficult approach you deal with index shifts, there must be topics about this?

the problem is in look, once the first o is removed, everyting to the right of the removed character shift to the left given the list can't have empty indexes, then the loop moves on to the next index skipping the second o of look

i know what you will ask, its becasue .remove() removes the first match it can find (so, once the loop encounters the o in words, the o in lok is removed


#3

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