Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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: