Why my code does not work? For Anti Vowel

`def anti_vowel(text):
    new = list(text)
    a = ""
    for i, j in enumerate(new):
        if j in "aeiouAEIOU":
            del new[i]
    a = a.join(new)       
    print a
print anti_vowel("Heay, AeeaaEIOUGGA")`

The output is wrong. Please help to fix it.

Purify: Iteration skipping entries, need help

why do you use enumerate? What purpose do it serve?

Using del as a solution for this kind of problem, is general a bad idea because of index shift. lets look at:

h   e   e   y
0   1   2   3

right, now if you get to the first e, it will be removed, the second e will shift to index 1, while the loop contains to index 2, so two vowels in a row causes a problem

I suggest you just append the items to a new list or string if it is not a vowel


Thanks bro. My first though to solve the problem is use index....and I had waste too much time on it.
Just try another method to solve it as advised


If further assistance on this exercise is required, make a new reply with your updated code. Good luck!


Hi, I used below code but the system did not let me pass this exam successfully. The result is correct.
Would you please check if below code is not suitable for this case?
Thank you.

It seems it work now. thank you.

def anti_vowel(text):
    new = ''
    for i in text:
        if i not in "aeiouAEIOU":
            new += i
    text = new
    return text
print anti_vowel("Hey You!")`


should work fine. Good to hear it works, next time try to use markup so indent will show on the forum


yeah, I used Preformatted Text to print it but sometime it does work...

I just go to have a BBQ with friends and back to home just use 5 mins to solove this problem which I was working on it about 1 hour....
Hope I can learn Python and get a job.. haha