8. anti_vowel


My code belows gets this message:

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

I'm not understanding why the "!" comes first and the rest of the string seems to be in order. Any ideas?

def anti_vowel(text):
    i = len(text)
    new_text = ""
    for i in range(len(text)):
        if text[i-1].lower() not in "aeiou":
            new_text += text[i-1]
    return new_text


why do in your if statement, and the line below use i-1? i is a perfect index match, no need to do minus one


D'oh, thanks for catching that. It's interesting that i-1 would take you to the "!" first...


make sense? you can use -1 to access the last item of a string? So it kind of make sense

for example:

print "see how this work"[-1]

will give you k


Gotcha. I wasn't sure how it worked so thanks for clarifying!