Anti_vowels


#1

Hello Guys, i dont get what is wrong with this source code:

def anti_vowel(text):
    
    text_lower_list = list(text)
    for value in text_lower_list:
        if value in "aeiouAEIOU":
             text_lower_list.remove(value)
    
    text = "".join(text_lower_list)
    return text

It gives me this 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!".
-
i mean it remove the "o"s of "look" but not the "o" of "Words"


#2

When an item is removed from the list, everything to the right of if shifts over to fill the void. That puts the next value in the position of the one that was just removed which means it gets skipped when the loop advances to the next position.

Your loop is actually skipping the second o in look, but because of how remove works, the last o remains. remove always takes out the first item it encounters from left to right.


#3

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