Anti-vowel not entirely anti-vowel


This is the error that I'm getting:
Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!".

I'm not sure why it is not removing the final "o".

def anti_vowel(text):
    new = list(text)
    for c in new:
        if c in "aeiouAEIOU":
    return ''.join(new)


@lconant Problem exists in this part of code..

for c in new:
        if c in "aeiouAEIOU":

When you start looping at new list and then check if it (vowel) is present in vowel string.
Suppose you find one ,then you just remove it.
In next loop,Your list is not same as last one as you removed one element of the list.(It's length have changed as you removed one item)
Thus it skips few items of list and you get "o" left (When CC checks at anti_vowel("Hey look Words!")).

Instead deleting from new..create separate copy of new list..then delete items from it and return (by using join() method on it to convert back it to string)

One more thing,the list you create should not have same reference as yournew list.
use this syntax to create this list..

new_list = new[:]
usenew_list as loops main list instead of new.

do reply if it solved the problem or not!


Yes! That solved it. Thank you!


I used a slightly different approach. I started with a new empty string newtext then pushed the letter to it if it was not in text. Looping through text with a for i in range command:

if text[i] not in "aAeEiIoOuU":


I got another solution! Use not in to get all other characters out of the list, append all these to another list and return that.

def anti_vowel(text):
txt = list(text)
new = []
for i in txt:
if i not in "aeiouAEIOU":
return "".join(new)


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