Anti_vowel, why isn't my code working?


#1



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

In my code am first converting the given string into a list and then removing the vowels using .remove()

For print anti_vowel("Hey You!") my code gives an output "h"

def anti_vowel(text):
    text = text.lower()
    sans_vowels = []
    for i in text:
        sans_vowels.append(i)
    for i in sans_vowels:
        if i == 'a' or i == 'e' or i == 'i' or i == 'o' \
        or i == 'u':
            sans_vowels.remove(i)
        else:
           return i
    return sans_vowel


#2

i don't recommend remove for this problem, it is a really great challenge to solve this problem with remove.

okay, now for the flaws in your code. First, understand that a function ends the moment a return keyword is reached, which happens in the first run of the loop:

else:
           return i

thanks to the above code.

and this line:

return sans_vowel

you forgot the s after vowels

now the code will still not work, because of index shift thanks to remove. I recommend appending constants to a new list, a lot easier


#3

Hey, I got it.
Thanks for the help.


#4