Remove Vowel


Hi There,
I have written below code to remove the vowel from a word/sentence but its not working for all type of entry.Like when I am entering Hey You! its removing only ‘e’ and ‘o’ .The code is working perfectly for some of the input.

def anti_vowel(text):
    in_list = []
    vowel_list = ['a','e','i','o','u','A','E','I','O','U']
    for i in text:
    #print in_list

    for i in in_list:
        if i in vowel_list:
    return ''.join(in_list)

input = raw_input("> ")
print anti_vowel(input)


that it works for some but not all strings isn’t good enough. What difference do you notice between the strings that are and are not working?

the answer to the above question, think about it before clicking on it:


strings which aren’t working have successive vowels

now the question is, what causes this problem? Again, think about this before clicking below


When removing vowels, everything to the right of the removed item shifts one place/index to the left given lists can’t have empty indexes, then the loop progresses to the next value in list, causing a successive vowel to be skipped.

Now, how could we solve this? Do you have any ideas?


For input ‘Roger’ :- Output coming ‘Rgr’ which is correct but
For input ‘Regain’:- Output coming as ‘Rgin’ which is not correct as still ‘i’ not removed


it feels like you answered none of the questions i asked, please answer my questions

How are these strings different? And what of this is relevant to your current problem?


Now I fixed the problem just creating a duplicate list of in_list and removing the letters from duplicate instead in original in_list.


isn’t that a bit inefficient? Maybe this indicates remove is not the right approach

do you also understand why that works?


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