anti_vowel loop won't complete


#1



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


For some reason, my loop won't complete. The error message is:

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


I can't understand why it won't loop thru the final word. I've tested the code out on outside IDE and the results seem to vary. For example, "Hello World!" will correctly return "Hll Wrld!", but some statements will leave out or fail to complete iterating on the final word. For example:

"Hello World! Hey look words!" >> "Hll Wrld! Hy lk words!"

Alternate test:

"Hello World! Hey look tacos!" >> "Hll Wrld! Hy lk tcos!"


Replace this line with your code. 

def anti_vowel(text):
    vowels = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u']
    check = list(text)
    for letter in check:
        for vowel in vowels:
            if vowel == letter:
                check.remove(letter)
    return ''.join(check)


#2

lets say we want to remove the vowels from look:

l   o   o   k
0   1   2   3

now, when the loop arrives at index 1, it will remove the o, but now we get a index shift. the second o moves to index 1, where as the loop continues to index 2, this way, the second o gets skipped. It is really difficult to use .remove to solve this problem, i recommend a different method, let me know if you need help with it


#3

Well, if you want a method that is a LOT easier but tedious as heck, try this:

def anti_vowel(text):
    AntiVText = ''
    for letter in text:
        if letter != 'a' and letter != 'e' and letter != 'i' and letter != 'o' and letter != 'u' and letter != 'A' and letter != 'E' and letter != 'I' and letter != 'O' and letter != 'U':
            AntiVText += letter
    return AntiVText

As you can see, it MANUALLY checks the letter it is inspecting against ALL different vowel combinations, and only adds it if all of these "vowels" do not match. The empty string fills up, and you get a string without any vowels.

I suggest using a different method to the one you were using too, so i gave you one! BTW this reply wasn't meant for stetim94, but it is somewhat related to his post.