Anti vowel


#1



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


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


def anti_vowel(text):
    for i in text:
        if i in "aeiouAEIOU":
            new=text.replace(i,"")
    return new


#2

you are replacing from text variable and storing the result in new variable

this means, textwill not be modified, so the last vowel replace, o, is the only this sticks, we can see this really nicely if we add some print statements:

def anti_vowel(text):
    for i in text:
        if i in "aeiouAEIOU":
            new=text.replace(i,"")
            print new
    return new

print anti_vowel("a best this do thus")

#3

I am not getting how to move forward. pls help


#4

But you see what is wrong, right? Only the last change replace action stands

So you want to store the string in the same variable as you are replacing from, so that after removing the a the string you are replacing from has no a, so that in the end, all vowels are removed


#5

i understand what you are saying.
but what i didnt understand is how to write the code.
i repalced the vowel but how to updat the original "text" variable simultaneously?
or should i store the removed vowels in a list and the remove those (something like that)?


#6

that is the easy part? We can simply store the result of the replace action in text variable rather then new variable


#8

Problem solved btw..thank you so much


#9

Its not a time waste, you learned valuable things :slight_smile:

good to hear problem is solved, you're welcome :slight_smile:


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.