8. Anti_Vowel


Hi people, I'm stuck on this what I believe is some sort of syntax error as the Python version I'm used to has slightly different syntax.
Here is my code:

def anti_vowel(text):
    vowels = ["a", "i", "e", "o", "u", "A", "I", "E", "O", "U"]
    anti = []
    for i in text:
        if i in vowels:
    return anti

and here is the error message:

Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "['H', 'y', ' ', 'l', 'k', ' ', 'W', 'r', 'd', 's', '!']" when it should return "Hy lk Wrds!".

So any help regarding this error will be appreciated! Thanks


you return a list, you should return a string. There are two things you can do, one change anti into a string:

anti = ""

and then append to the string:

anti += i

but this is an extensive operation,recommended is to use "".join() in your current code:

return "".join(anti)

join is a built in function, which joins a list into a string. the "" indicates what is used for the joining.


Thanks for the reply! It worked out with the changing it into a string but can see how it can get extensive with longer codes/programs.The join function seems the more logical solution out of the two though.


sorry, i should clarify. What i mean is that when using the first solution i showed you (with the string), you can't add to a string, a copy has to be made of the string each time. Which is not really nice for the performance of your program.

I said the join was the recommended method? Either way, good to hear you passed. also, you could use the not keyword:

if i not in vowels:

this means you don't need an else.


I see, thanks for the feedback, really helped me!