Hi I am stuck with the anti_vowel exercise (

I was able to change the vowels for a "", but I'm not sure I'm approaching the problem in the most helpful way. I've then used the join command to get a phrase but that didn't happen.

Here is the code. Someone could help me please? Thanks!

def anti_vowel(text):
    text = text.lower()
    for c in text:
      if c == "a" or c == "e" or c == "i" or c == "o" or c == "u" :
        c = ""
      text = text.join(c)
      print text
    return text   
anti_vowel("Hey there! Are you OK?")


why use .join()? .join() is used to join a list into a string

I don't see how this is very useful from your program, what other possibilities do you have?


When I did this exercise, I tried to approach it in a similar way at first.
I found I could save a lot of code if I assigned all the vowels to a list variable, which I could then just loop over the list to see if the character was a vowel or not. If not a vowel I would append it to a new list which we can join back together later.

vowels = ['a','e','i','o','u']
result = []

And I found I could simplfy my code by using the .lower method in my loop. This allows us to check it converted to lowercase, just for the check. Leaving it unmodified for or results.

for char in text:
    if char.lower() not in vowels:

Then all that is left to do is call our join method. This is where I see an error in your code. But I admit I'm still a novice and perhaps that join statment does work... however, this is how I approached it.

return "".join(result)

Takes our new list we created "result" and joins the elements together with "".

Hope this was helpful.


Hey betawhiz44877,

Thank you so much. I didn't think of using appending and joining! The one thing I don't fully understand is what the "" in "".join(result is doing. Anyone could explain pls?

I actually made some changes to what you were suggesting, as the editor was giving me errors. Here is the final code:

def anti_vowel(text):
    vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] #all vowels, coz the solution wants to keep the consonant uppercase
    result = []
    for c in text:
      if c not in vowels:
    print "".join(result)  
    return "".join(result)  
anti_vowel("Hey there! Are you OK?")


the character between "" of join, indicates what join uses to join the list into a string, for example:

print "-".join([a,b,c])

would give:



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