Anti-vowel problem!


#1


Anti-vowel exercise


Hello everybody, my code seems to be working but not always (and I cannot figure out why).
It works for all the cases but the "o" in Words(in "Hey look Words!").However it works when I replace "Words" with "Wards", "Wirds" , "Werds" or "Wurds" but then it stops working with "look" .
Please somebody help me, it really puzzles me.


def anti_vowel (text):
    a=[]
    b=[]
    
    for i in text:
        a.append(i)
    
    for k in "aeuioAEUIO":
        b.append(k)
        
    for z in a:
        for x in b:
            if z==x:
                a.remove(z)
    
    j=''
    for c in a:
        j=j+c
    
 
    return j


#2

remove is just a difficult way to solve this problem. I do not recommend, try appending the constants to a new list, that is much easier. Give me a second, and i will explain why remove is such a difficult solution


#3

the problem is in look, because of what happens in the moment of removal.

strings (and list) can't have empty indexes, so what happens when we loop over look and the first o of look gets removed? the indexes shift, lets illustrate this:

l   o   o   k
0   1   2   3

then after the removal of the first o:

l   o   k
0   1   2

however, the loop will move on to next item (which is k) so the second o gets skipped (due to the index shift)

why then if the sentence is Hey look Words!, gets the second o in look removed? the built in function remove() you use, will remove the first instance it finds, so the moment the o in words is encountered, the o in lok gets removed


#4

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