Anti Vowel


#1


anti_vowel

My code is not detecting the vowel in the word "Words".
I am getting this error:
Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!".

def anti_vowel(text):
s = []
for i in text:
    s.append(i)    
for i in s:
    if i == "A" or i == "E" or i == "I" or i == "O" or i == "U" or i == "a" or i == "e" or i == "i" or i == "o" or i == "u":
        s.remove(i)

t = ""
for i in s:
    t+=i
return t

#2

This is because of the way remove works. It doesn't take the element that is at the current index pointer, but the first one it encounters from the left side of the list. This will need a little tweak to correct that.


#3

Then how can i remove the current item?


#4

The simplest way is to consider that you have two iterables. The input string, and a list of vowels (as opposed to a whole if expression). Iterate the vowels, and remove each one from the input string. No need to verify, just use while.


#5

thanks for the help. got the solution


#6

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