When I run the program for anti_vowel("Hey look Words!") it returns "Hy lk Words!" when the o in words should be gone. I honestly don't know what's wrong and need help

def anti_vowel(text):
    final_string = ""
    cool = [ ] 
    for new_list in text:
    for x in cool:
        for y in "aeiouAEIOU":
            if x is y:
    for z in cool:
        final_string += z
    return final_string
print anti_vowel("Hey look Words!")

Anti_vowel HELP!

The .remove() method has not been covered yet in any of the previous units (afaik) so should not be used for this exercise (by rights). Use what we know up to this point to solve this.

We don't need to do this:


In a sense, we don't need any lists in this function. Just a text_final string.

text_final = ""
for letter in text:
    if letter not in "aeiouAEIOU":
        text_final += letter

Examples using built-in methods.

The str.replace() method, is greedy uness we specify a count. When there is no maximum, it replaces all instances it encounters. We only need to iterate the vowels list.

>>> def anti_vowel(text):
    for vowel in "aeiouAEIOU":
        text = text.replace(vowel, '')
    return text

>>> print (anti_vowel("Hey look Words!"))
Hy lk Wrds!

The list.remove() method removes only the first instance it encounters. That means we need to keep searching the string for more instances of the target object.

A simple way to do this on one object, is with a list off the top.

>>> def remove_vowel(text):
    text = list(text)
    for item in "aeiouAEIOU":
        while item in text:
    return "".join(text)

>>> print (remove_vowel("Hey look Words!"))
Hy lk Wrds!

We use list() so the spaces are preserved. Note that there is no separator in the returned join.


Thanks, that helped!


.remove() has been used in the course before this one. I have taken the coarse up to this point and my hand written notes are all from the course.


Good to know, though we still run into many cases where the learner has not done their follow-up study to learn how to properly implement the method, so get everything in a knot. I'll stand by my advice to not use the built-in unless asked for, but then that's just me.

Did you happen to note which module/lesson this is brought up?


I agree with you on the early coarse stuff when it comes to using what it wants you to use to complete the lesson. I think thought at this point in the course I it gives you more room to apply everything you have learned and get creative.

The section I have written down for the .remove() is "Python Lists and Dictionaries" in section 13 "Remove a Few Things".


Ah yes, that would be a sensible place to cover the method.

Try everything, yes. In other words, do the task in as many different ways as we may conceive of, in both basic terms and more advanced approaches. Practice, practice, practice.


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