Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Lists Disemvowel

I don't know what is wrong with this coding

I tried to use the remove method but failed, and I hope you could help me fix my code

disemvowel.py
def disemvowel(word):
    vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    for letter in word: 
        if letter in vowels:
            word.remove(letter)
    return word

1 Answer

Steven Parker
Steven Parker
229,744 Points

Strings don't have a "remove" method, were you thinking of using "replace"?

So if I want to use the remove method, I have to change the string into list first? But I am not sure how to do this. I actually want to use the remove method not replace

Steven Parker
Steven Parker
229,744 Points

Sure, that's another way to go. Change the string to a list, make the changes to it with "remove", and then join it back into a string to return it.

If you go that way, be sure to use a copy of the list for looping to avoid problems with items being skipped.