8 Anti Vowel Quick Question


#1

Can someone let me know why this doesn't work?

The error I get is:
"Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "None" when it should return "Hy lk Wrds!"."

def anti_vowel(text):
    text=text.lower()
    for i in text:
        if i == ["a","e","i","o","u"]:
            return text - i

#3

I took quite a different approach, and it is some seriously ugly code, but after trying strings containing vowels and lists containing vowels...i had no luck, but this line of code works...
I can't guarantee that this despicable code will help you, but it does work.

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

#4

If I'm not mistaken, we are expected to leave the case as input, and strip both lower and upper case vowels.

The above line is equating a single character (a string object) to a list object. It will never match. The in operator is very useful in cases such as this.

This cannot be done. To remove a character we use text.remove(i), but never in a loop. The following creates a new list of accepted characters, then returns a string.

def anti_vowel(text):
    x = []
    for i in text:
        if i.lower() not in 'aeiou':
            x.append(i)
    return ''.join(x)

#5

Much obliged. Thank you!