"Spring with Hibernate" was retired on January 8, 2022.

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

Patricia Snyder
Patricia Snyder
5,563 Points

Received unexpected letters

Hi, The below code worked outside of the challenge but it doesn't work inside. Can someone spot the problem?

Also, what is a cleaner way to do this? There must be a better way than adding try and except for each vowel.

Thank you. Trish

disemvowel.py
def disemvowel(word):
    word = word.lower()
    wordstring = [] 
    for i in word: 
        wordstring.append(i)  
    for i in wordstring:
        try:
            wordstring.remove('a')
        except ValueError:
            pass
        try:
            wordstring.remove('e')
        except ValueError:
            pass
        try:
            wordstring.remove('i')
        except ValueError:
            pass
        try:
            wordstring.remove('o')
        except ValueError:
            pass
        try:
            wordstring.remove('u')
        except ValueError:
            pass

    return wordstring

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

There are two issues with the current code:

  • wordstring needs to be joined back into a single word
  • The capital letters are not preserved in the returned word. Be mindful of how you are using lower()

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

Patricia Snyder
Patricia Snyder
5,563 Points

Thank you! I got it to work. I also found a better way to solve the problem using the str.replace() method.