15. Anti-vowel


#1



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


I get the error message; "'str' object has no attribute 'remove'" error. I don't know what the means or what I am missing here. Any help is appreciated.


def anti_vowel(text):
    vowels = ['a','e','i','o','u','A','E','I','O','U']
    for v in text:
        if v in vowels:
            text.remove(v)
            return text
        else:
            return text


#2

string is of immutable data type.. so remove() method does not work for it.

hint**
remove() works for list.. so try converting string to list then when you remove all vowels ,you can convert it back to string ?


#3

The error is that .remove is a method that works for lists only , so you have to convert the input to a list & then convert that list to a string again

Explanation:

def anti_vowel(text):
    vowels = ['a','e','i','o','u','A','E','I','O','U']
    l = list(text)
    for v in l:
        if v in vowels:
            l.remove(v)

I hope you understand the error , & NOW you have to complete this code in order to make your code Functioning correctly


#4

Thanks to both of you, that was helpful. Here is my completed code. Would be interested in your input if you would have gone about it differently than what I have below.

def anti_vowel(text):
    vowels = "aeiouAEIOU"
    vlist = list(vowels)
    tlist = list(text)
    for t in text:
        if t in vlist:
            tlist.remove(t)
    return ''.join(tlist)

#5

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