Remove Vowel


#1

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:
        in_list.append(i)
    #print in_list

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

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


#2

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:

Problem

strings which aren’t working have successive vowels

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

Problem

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?


#3

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


#4

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?


#5

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


#6

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

do you also understand why that works?


#7

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