8. anti_vowel works fine, but ignores one "o"


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096


Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!".


So, I don't really understand what's going on at all. It works completely fine everywhere, except that one "o" in "Words". What is it, magic? That "o" is special, and "o" in "look" are not? I'm pretty sure my code is okay, but something's wrong, and I can't find it for few days at this point. Please, help


def anti_vowel(text):
    check = 'aeiouAEIOU'
    text = list(text)
    for a in text:
        if a in check:
            text.remove(a)
    text = ''.join(text)
    return text


#2

It's easier to build a new string out of the characters that do not appear in
'check'.

new_string = ""
for a in text:
    if a not in check:
        new_string += a

et cetera


#3

Yea, I've found some code with building new string, that works. But it's more interesting to make your own code work. Anyway, it seems, that after digging more deeply in the forum (omg, I have not noticed QaA topic, now I feel dumb) I kinda understand the cause of that problem...Deleting elements from the list kinda screw the indexes - where there was an 'y' now is ' '. At least, I think that's the cause, because I can't really wrap my mind around that with my knowledge of Python at the moment :slight_smile: Anyway, thanks for reply.


#4

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