Anti-vowel problem!


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):
    for i in text:
    for k in "aeuioAEUIO":
    for z in a:
        for x in b:
            if z==x:
    for c in a:
    return j


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


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


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