Anti_vowel most vowels removed


#1



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


It eliminates all vowels except for the final "o".

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


All vowels should be removed.


text = "Hey look Words!"

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


#2

no, because you are dealing with index shift. lets do an example:

l   o    o   k
0    1   2   3

the moment you remove the o at index 1, everything to the right of the removed item shifts one index to the left:

l   o   k
0   1   2

given strings (and lists) can't have empty indexes. Now the loop continue to index 2 (which now contains k), so successive vowels are not handled correctly.

solution: you can loop over the string while removing from the list, no items are skipped in string because you are not removing from string.


#3

Ah, thank you. I was wondering if it was index related. Changed it to "for letter in text:" and it works now.


#4

I tryed your code with diffrent words , and i noticed that when a word contains 2 vowels in the row, it takes only one and leave the other !


#6