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

Kamontat swasdikulavath
Kamontat swasdikulavath
2,447 Points

OK, I need you to finish writing a function for me. The function disemvowel takes a single word as a parameter and then

I tried doing it my way, why isn't it working?

disemvowel.py
def disemvowel(word):
    list(word)
    word.remove('a')
    word.remove('e')
    word.remove('i')
    word.remove('o')
    word.remove('u')
    word.remove('A')
    word.remove('E')
    word.remove('I')
    word.remove('O')
    word.remove('U')
    ''.join(word)
    return word

1 Answer

Hi there, A couple of things I can help with. First, are you first trying this on your own python interpretor? some of the error messages can really help. If you're not able to install python on the machine you're using, might I suggest this online python environment to test code? https://www.tutorialspoint.com/execute_python3_online.php

Now, down to a couple of problems. First, you're absolutely spot on that passing a string into list's constructor will return a list of its characters, but you have to asign that returned value to something.

word = list(word)

Would work for example.

The next problem you're going to have is what will happen with word.remove("x") if the x isn't in the list for it to remove. It will raise an ValueError and halt your program. You could first check if the value is in the list, or use a try/except statement to handle this.

Finally individually removing chars like this line by line can be difficult to maintain or scale ( what if you instead wanted to remove all consonants? or all punctuation? That's a lot of typing) I recommend using a loop, list comprehension or looking up the filter() method :)

Best of luck