Anti-vowel not working


#1




I know that there are many ways to complete this exercise and that I don't have to do it my way, but I would like to know why my code isn't working for future reference. It removes the 'o's in "look" but doesn't remove the 'o' in "Words". Thanks in advance! :slight_smile:


def anti_vowel(text):
    my_list = []
    for letter in text:
        my_list.append(letter)
    for item in my_list:
        if item == "a" or item == "A" or item == "e" or item == "E" or item == "i" or item == "I" or item == "o" or item == "O" or item == "u" or item == "U":
            my_list.remove(item)

    final = ''.join(my_list)
    return final


#3

Removing an element in a list causes the following elements to move to one index lower which you are not accounting for. (All that moving is also redundant to what you're trying to achieve so list.remove is not what you'll want to be using as it just doesn't do what you want)

Also, this:

my_list = []
for letter in text:
    my_list.append(letter)

Is equivalent to:

my_list = list(text)

#5

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