Help with anti_vowel code


#1

can someone please check the code below?
when i manually put a print statement it removes the vowels in the editor, but the editor puts out a message that it would print out bcdHy lk Wrds!. when i enter the command print anti_vowel("Hey look Words!") it prints it correctly in the editor but still the message that my code did not pass, can anyone help me with this?

thank you,

a=[]
s=""
def anti_vowel(text):
for i in text:
if check_vowel(i):
a.append(i)
return "".join(a)

def check_vowel(i):
if i in "aeiouAEIOU":
return False
else:
return True

print anti_vowel("Hey look Words!")


#2

I found the solution in another thread, that the list needs to be in the function i don't understand exactly why but it works that way.
here is the link to the answer.


#3

Hi, I am a new Python same as you.Below code is for your reference.You may think about it and help you.

def anti_vowel(text):
vowel = []
for i in text:
vowel.append(i)
for i in vowel:
if i in "aeiouAEIOU":
vowel.remove(i)
text = vowel
return "".join(text)

print anti_vowel("Hey look Words!")


#4

I can't figure out what's wrong with my code. Especially because the output is so close to what it should be:

error message:
Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!".

code:

def anti_vowel(text):
    text = list(text)
    for char in text:
        if char in "aeiouAEIOU":
            text.remove(char)
    return ''.join(text)

#5

Yes, this does look strange, but the answer is that your for is moving up the string while your remove function shortens the string.
so every time you are deleting a vowel, the next char you are not checking because the list moved up.
for example if you check just the word "load", your for will check "l" and it will be ok > it will check "o" and will remove and shorten your string so it will not check "a" but will check "d" and you will be left out with "lad".
hope this helps.