Anti_vowel - bugged?


#1



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


I tried this exercise a million times, (even after I copied code from an earlier post comment by moderator stetim94, it wouldn't work)
Problem is the 'e' won't be removed
Thankful for help


 def anti_vowel(text):
    for c in text:
        if c in 'AEIOUaeiou':
           x = text.replace(c,'')
           print x
    return x
print anti_vowel("Hey look Words!")


#2

as you can see in the output window, e does get removed (first line in the output window)

text contains the string we want to remove the vowels from.

so we loop over text, and if we find a vowel, we replace the vowel with an empty string.

the problem is, you replace characters from text and store the result of this replace action in variable x.
This won't work, because text will keep all its vowels, so the last replace action eventually ends up in the variable x.

when replacing vowels with empty strings, store in text, so text gets updated.

you can see this much better if you where to do something like:

print anti_vowel("dust do this he as")

#3

Oh! Finally got it, God bless you


#4