Getting wrong output for removing vowels


#1

def anti_vowel(text):
    s = list(text)
    for i in s:
        if i == 'a' or i == 'A' or i == 'e' or i =='E' or i == 'u' or i =='U' or i == 'i' or i =='I' or i == 'o' or i =='O':
            s.remove(i)
    text = ''.join(s)
    return text

Tester says : Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!".


#2

Hi @betaslayer03406,

Iterating though a list as you change its size interferes with the iteration.

Instead, you should initialize a new empty list, and append characters that are not vowels to that list, as you iterate through text.

After the loop, pass that list to the join method to produce the result.


#3

Yep got it !
Thanks :slight_smile:


#4