[solved]Remove method not working for me


#1
def anti_vowel(text):
    vowel = ["a","e","i","o","u" ]
    for letter in text:
        if letter in vowel:
            text.remove(letter)
    return text

I figured out the issue using a method involving me using 'not in text' rather than what's there originally. So I completed this lesson.

But I can't seem to figure out why "text.remove(letter)" always seems to catch a "str has no attribute remove' exception. I thought that the format was list.remove(str) and since "letter" served as the variable for each letter in the original word that this code should work fine.

What am I missing here to make this code work?


#2

your vowel is a list, but your text is not. And you can call remove on text (text.remove) while remove is a function used to remove items from a list, not a string (text is a string)

You could use .replace() or you could make a new string, and push hits to it. Don't forget strings are indexed as well. text[0] is the first char, text[1] the second character, and so on.

I am not going to tell you the full solution, that would be a waste of the learning momentum.


#3

Alright, cool.

I already completed this lesson using a different method, I was just curious as to why that method wasn't working.

Thanks a bunch.