Hi, I am very stuck on the exercise anti_vowel, could some one help me please.

Define a function called anti_vowel that takes one string, text, as input and returns the text with all of the vowels removed.

For example: anti_vowel(“Hey You!”) should return “Hy Y!”. Don’t count Y as a vowel. Make sure to remove lowercase and uppercase vowels.

My code:

def anti_vowel(text):
  text = ""
  if text == "aeiouAEIOU":
  return text


You are overthinking this. Try following this template:

        if INDIVDUAL_ITEM in "aeiouAEIOU":
    return PARAMETER

Make sure not to just follow the template and move on. I want to make sure that you understand how and why this works. If you have any questions, just ask.


If one has just set text as the empty string, how can it be the same as a non-empty string? And what’s more, the parameter is text and text = "" completely overwrites it so the input is lost.

Give your temporary variable a name that does not overwrite the inputs.

def anti_vowel(text):
    new_text = ""

Now the input is left intact.

As for using the del function, that may be a bit more advanced than needs be. We have the tools to solve this problem without reaching for built in functions that we perhaps do not yet have a full grasp of. Granted, there may be a way to use the function, but one thinks it better to work with the basic tools and build an algorithm to arrive at a working solution.


Thank you very much for the help.


Hi, thank you very much for the help and sorry for overthinking it.
The template helped a lot, could you explain to me what this, text = text.replace(i, “”) is and how it works please.



All this line is doing is setting text equal to the result of calling text.replace("i", "").

.replace() is a built in function for strings. It is used to replace a character (or characters) within a string with something. The way it is used here, it is replacing i in text with "" (empty string). By replacing a character (or characters) with an empty string, you have effectively removed these characters from the string. For instance:

my_word = "egg"

my_word = my_word.replace("e", "")

print my_word # my_word now equals "gg"

For more information on how the .replace() function works, check out the documentation.


Thank you, I understand it a lot more now!


What is learned by using the built-in? Nothing. This exercise is about building algorithms that show the step by step process of detecting and removing vowels. If you let this exercise go with what solution you have now, you will be missing out on a lot and only find yourself in the same hole weeks from now. Build an algorithm before leaving this exercise.


Hi, thank you for the help, would say because I have struggled on this course a lot I should re-do it all after finishing it all, or re-do all of the python course? And sorry if this sounds like a dumb but how do I build an algorithm?


Review is actually a lot more than just redoing the lessons. It is exploring every lesson through reading, experimentation and repetition. The lesson is the easy part. Building upon the lesson (without introducing concepts that follow it) is where the work really takes place. Once we do that, we can be sure our toolbox has a new tool that we know how to use.

Let’s look at the pattern suggested above by @aquaphoenix17. It is sort of an algorithm, but all the heavy lifting is done by the built-in. The following does its own lifting…

def anti_vowel(text):
    new_text = ''
    for letter in text:
        if letter not in "aeiouAEIOU":
            new_text += letter
    return new_text

The above iterative algorithm examines the text one letter at a time and checks to see if the letter is not found in the vowel string in which case it replaces the new_text string with one that includes the current letter.


new_text = new_text + letter

Strings are immutable. The only way we can modify them is to replace them with the modified form derived from the expression (concatenation).


Hi, whats the best way to build upon the lessons? I was very stuck on that question, I over complicated it, but when @aquaphoenix17 gave me a template, I understood it.


You are sort of doing that by exploring the built-in function approach, especially if it was introduced at some point before this exercise (in the lesson track). Building on only what we have been introduced to at a given point means honing one’s skills with just those tools.

Master each module before going forward. As simple as they may seem, look for alternate ways to put the pieces together to arrive at a desired solution. These practice makes perfect exercises are the reminder (real eyeopener for many) of what building work we may have neglected up to this point. It’s why people hit a wall, here.

Racing through the first set of units without review is how not to build upon what we have been introduced to. Nothing will stick, and we will not have the mental prowess to design an algorithm. If we are stumbling on code awareness, we are not going to be thinking through the problem and formulating ideas in our mind.

Programming is not a rote science. There are best practices, yes, but beyond that the sky is the limit and we need to expand our brain and imagination early on. We cannot be creative working from templates, alone. The code patterns we teach ourselves through experimentation (trial and error) are the ones that we will carry into the future.

Anyway, it sounds like I’m harping, now. Bottom line is to take your time and study every concept thoroughly so you begin to recognize the moving parts of a program and how to design one for any given problem. Happy coding!


Thank you for all the help and advice, means a lot. You have woke me up and realised rushing is not the way to go and gave me a better understanding on how to work for the long run, thank you again. Quick question did you learn python on Codecademy?


Yes. Previous to 2013 I’d never used anything but JS and PHP, and only as a self-learner solving problems by seat of the pants.


Wow you’ve been doing it for a while then, Im doing the command line course after to help with learning penetration testing.


My apologies @mtf. I forgot that .replace() hadn’t been introduced yet at this point in the lessons. Had I remembered this, I would have suggested something similar to your example.


A post was split to a new topic: Anti-vowel: Can you help and explain why it’s error?