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

Jesse Ferguson
Jesse Ferguson
1,419 Points

I'm stuck

I don't know how to do this

disemvowel.py
def disemvowel(word):
    try:
        word.remove('a')
        word.remove('A')
        word.remove('E')
        word.remove('e')
        word.remove('I')
        word.remove('i')
        word.remove('O')
        word.remove('o')
        word.remove('U')
        word.remove('u')
    except ValueError:
        pass
    return word

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,989 Points

Your approach doesn't handle these cases:

  • if the word is a string, strings do not have a remove method
  • any vowel appearing more than once will not be removed
  • if any vowel is not found the try block to exit then return the current state of word

Suggestion: convert the word to a list then use a for loop to extract the non-vowels rejoin the non-vowels back into a string and return it.

Post back if you need more help. Good luck!!!