Anti-vowel


#1



I've been having issues with the Anti Vowel exercise. I had an idea to convert the string to a list, then use a while loop to iterate through it and replace the vowels.


I'm not getting an error in complier, but when I run it I get this error from code academy:

Oops, try again. Your code looks a bit off--it threw a "list index out of range" error. Check the Hint if you need help!


I'm not sure how the list index is out of range when I'm setting it to the length of the list. Is there something I'm missing?


def anti_vowel(text):
    count = 0
    new = list(text)
    max_count = len(text)
    while count < max_count:
        if new[count] not in "aeiouAEIOU":
            new.pop(count)
        count += 1
    str(new)
    return new


#2

Indexes won't match after you've removed an element from the list, you'll run into the same problem if you try to execute your algorithm manually.

Also note that removing elements far away from the end is a lot of extra work, consider how much time that takes if the text is something like a long book, having to move everything that follows the removed character to fill the location where an element was removed


#3

Okay, I didn't think about how removing letters changed the index. I found a better way to solve the exercise, but I wanted to figure out what was wrong with my original attempt.


#4

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