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

drstrangequark
drstrangequark
8,273 Points

Remove doesn't work on a string?

The code challenge is to remove all the vowels from a word. When I run the attached code I get an error saying that strings don't have the remove function? Do I need to turn "word" into a list?

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

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Yes, to use the remove method, you will need to turn it into a list. This method is only available on lists. That being said, bear in mind that using remove on the item you're iterating over will produce some unexpected results as it will be altering the indexing of the iterable.

Good luck! :sparkles: