8. Anti-Vowel


Hi folks,

i write this code outside of codecademy, and it passed (Ie. it prints the string without vowels). I am getting the following error when I type it in here, despite the fact that it also works here. Any ideas? Somehow I neglected to see that I hadn't returned the calculation... Off to bed I go.

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):
    less = ""
    vowels = ["A", "a", "E", "e", "I", "i", "O", "o", "U", "u"]
    for i in text:
        if i not in vowels:
            less = less + i
    print less
    **return less**
anti_vowel("Hiya dear friend")


I have some magic for you!

class WordWizard:
    def __init__(self):
        self.name = "Word Wizard"
    def _remove_vowels_spell(self, word):
        return ''.join([letter for letter in word if letter.lower() not in 'aeiou'])
    def _cast_spell(self, *spell):
        words = []
        for word in spell:
        return words
    def __call__(self, *args, **kwargs):
        print("I will change your words! For the better of course. See: ",*self._cast_spell(*args))
    def __str__(self):
        return "My name is %s, nice to meet you!" % self.name

Then we must summon our Wizard!

summon = WordWizard()

Let's call on our wizard!


What impudence! His response was I will change your words! For the better of course. See: ppl.

You only need to do

def remove_vowels(self, word):
        return ''.join([letter for letter in word if letter.lower() not in 'aeiou'])


Hahaha! This was amusing. Love a good wizard. But do you know why my code isn't passing, despite displaying correctly? I already passed this test, but I wanted to go back and try a different solution. Now it won't pass :frowning:


I was about to put that in there that you didn't return. Beat me to it! lol


I have problem also

def anti_vowel(text):
vowel = ["A","E","I","O","U","a","e","i","o","u"]
x = []
b = []
s = ""
for f in text:
print x
for i in x:
print "text =" + i
for z in vowel:
print "vowel =" + z
if i == z:
n = "remove"
print n
print x
elif i != z:
n = "still"
print n
return s.join(x)
print s.join(x)

the result are like this

anti_vowel("Hey Look Words")

Hy Lk Words

I'm not sure why
Please help


Hi everyone,

I am having an issue with mine and I can't seem to find the error. Thanks for taking a look.

vowels = ["A", "E", "I", "O", "U", "a", "e", "i", "o", "u"]

def anti_vowel(text):
output = ""
for char in range(len(text)):
consonant = True
for vowel in vowels:
if char == vowel:
consonant = False
if consonant == True:
output += text[char]
return output


My code works:

def anti_vowel(text):
    for i in "aeiouAEIOU":
        text = text.replace(i,"")
    return text


That's ingenious.

Good job!


Would you mind explaining the "text.replace" line you have used there? have'nt quite wrapped my head around that well.


def anti_vowel(text):

Vowel =["A","E","I","O","U","a","e","i","o","u"]
for c in  text:
    if c not in Vowel:

return anti


Here's how i did it

def anti_vowel(text): #creating a function with an argument called 'text'.
    removal = "" #making an empty string to which we are gonna add onto later.
    vowels = ['a','e','i','o','u','A','E','I','O','U'] # list of the vowels.
    for i in text: #iterating through each letter in the 'text'.
        if i not in vowels: #says it in the code             
            removal = removal + i #adding the letter that wasn't in the 'vowel' list onto the new one we created earlier
    return removal #you know what this does.

print anti_vowel('Hey there! how you doing?')

With some help from @rubyblaster52470 code above.


concise and effective, thank you for this solution.


One day I want to be a Wizard like you zeziba! But today, I will have to settle for apprentice.

Thanks zeziba!


My code

def anti_vowel(text):
    removtext = []
    for c in text:
        if c in "aeiouAEIOU":
    return ''.join(removtext)


have developed almost a similar code.

def anti_vowel(text):
for x in text:
if x not in 'aeiouAEIOU':
return text1


Here's my code. I'm suprised no one used the .lower() fuction besides me.

def anti_vowel(text):
    text1 = str(text)
    phrase = ""
    for char in text1:
        if char.lower() == "a" or char.lower() == "e" or char.lower() == "u" or char.lower() == "o" or char.lower() == "i":
            phrase +=char
    return phrase
print anti_vowel("Hey look Words!")


Did you figure it out?

He's looping through the vowels, then replacing all vowels found in the variable 'TEXT' with empty strings ("") so it will output no vowels in 'TEXT' when printing in the console so Codecademy will take it as good and valid.

Great Job for jmacalua!


For the appreciation of lists:

string = raw_input("Type something here: ")

vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]

def anti_vowel(text):
	textlist = []
	for i in text:
	for j in vowels:
		while j in textlist:
	text = "".join(textlist)
	print text
	return text


I thought my code is quite good until I read this topic. :smiley:
At least it works.


Clean, simple and effective. Nice work!