Stuck in anti_vowel()


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

I would expect it to work, I can't find out what's the mistake. Could you guys please help me out?
Thanks in advance!

def anti_vowel(text):
    vowels = "aeiouAEIOU"
    res = ""
    for t in text:
        for v in vowels:
            if t == v:
                res = res+""
                res = res+t
    return res


The logic would seem sound, but...

When t does not equal the current vowel, v, your else branch is affixing the letter to the result string without completing the vowel loop.

We may forego that inner loop and use an if statement with not in vowels...

if t not in vowels:
    res += t


Wow! Didn't think of that, thanks a lot for the suggestion, now it works fine!

By the way, it's very nice how a number appears instead of my user name when you quote me :stuck_out_tongue:
I hope a moderator sees it and fixes it in the forum.

Thanks again!


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