8. anti_vowel


so my code returns "Hy lk Words!"
why is it not removing the last o?

def anti_vowel(text):
    vowels = "aeiouAEIOU"
    no_vowel = []
    for i in text:
    for i in no_vowel:
        for x in vowels:
            if i == x:
    return "".join(no_vowel)
print anti_vowel("Hey look Words!")


How does removing an element affect the iteration through that same list?


I was adding the full text to the empty list, then I removed the vowels


Yes, and as you remove them, how does that affect your loop?


theoretically, it's supposed to remove the vowels but for some reason it didn't remove the third o


Does your loop reach the third o? Something to do with removals affecting the loop perhaps?


That makes sense. After removing the letter, the loop is moving to the next coordinate, not the next letter


should I restart the loop every time I remove a letter?


I suggest creating a new list, filling it up with just what you want to keep. That also ends up being faster, removing is pretty expensive since it requires all following elements to scoot up one notch to cover the empty slot.


Ohhhhhhhhh ok thanks.


Hope this may be of interest. Came up with this code snippet which seemed much simpler using python's List Comprehension

def anti_vowel(text):

vtext=''.join(letter for letter in text if letter not in vowels)
return vtext

print anti_vowel("Hey look Words!")