Help! anti_vowel


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

def anti_vowel(text):
    string = []
    for i in text:
    for i in string:
        if i == "a" or i == "A" or i == "e" or i == "E" \
        or i == "i" or i == "I" or i == "o" or i == "O" \
        or i == "u" or i == "U":
    return "".join(string)


.remove() is a difficult approach given you deal with index shifts (everything to the right of a removed item will shift one index to the left given list and strings can't have empty indexes)

this cause succesive vowels to be skipped, because the loop moves on to the next index

index shifts only occurs when you remove from the same list as you are looping over, so you could loop over text and then remove from string, that is fine.

Or you could go for the opposite solution, appending constanants to a new list


instead of:
for i in string
because the remove function changes the index (as mentioned by stetim94), you can loop backwards so that the index doesn't matter

for i in reversed(string)
would work :slight_smile:


True, but .remove() will remove the first match it can find, so it feels fragile but i think that is a personal opinion


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