Anti-vowels


#1



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


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

at every point, one vowel is left behind


def anti_vowel(text):
    x=[]
    for letter in text:
        x.append(letter)
    for item in x:
        if item in 'aeiouAEIOU':
            x.remove(item)
    return "".join(x)


#2

list can't have empty indexes, so the moment you remove something everything to the right of the removed item shifts one index to the left (filling the gap) then the loop moves on to next index, causing the succesive vowel to be skipped


#3

Okay thanks! I am unable to fix it though. What should I be changing?


#4

i usually advise not to use .remove(), because its quit difficult

The opposite approach (appending constonants to a new list) is much easier

If you really want to use .remove(), the "easiest" thing to do is to loop over text while removing from x

because you are not removing from the same list as you are looping over, you don't have a problem with index shifts


#5

Great thanks! Got it


#6