8. Anti Vowel (explain like i'm five)


#1



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


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


This entire section has me stumped, but I thought I understood how to do this excersize. However, I can't figure out why it's NOT getting rid of the 'o' in 'Words!'

please help :cry: I'm so frusterated!


def anti_vowel(text):
    text_list = []
    for char in text:
        text_list.append(char)
    for x in text_list:
        if x == 'a' or x == 'e' or x == 'i' or x == 'o' or x == 'u':
            text_list.remove(x)
    print "".join(text_list)
    return "".join(text_list)
    
anti_vowel('becky')


#2

.remove() is a difficult approach given index shifts will occur (causing problem with successive vowels)


#3

What approach would you advise?


#4

either make an empty list/string (your choice which is wiser, or which you are more comfortable with) and append/add constants to the list/string

or do you really want to make it work with remove()? (which i advise against)


#5

OH, okay! so i was kind of on the right track, but not quite there.

I don't have any particular desire to use .remove(), it was just the only way I could think of to complete it. thank you! i'll be more wary of using remove() in the future


#6

The behaviour of list.remove is to start from the beginning of the list and compare each element to the value you gave to remove.
When a value matches (==), that element is removed, and all the following elements are then moved one position forwards to fill the empty location caused by the removal

There's a lot there that isn't appropriate for getting rid of vowels, it's doing more undesirable things than desirable ones


#7

thank you, now it makes sense why my code was skipping over the 'o' in words! I appreciate the feedback :slight_smile:


#8

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