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

Am I using my try block properly?

I may misunderstand the logic of the try block. Can anyone help with a reiteration of what Kenneth has taught...also let me know what else you may see wrong with the code.

Thanks in advance

disemvowel.py
def disemvowel(word):
    vowels=["a","e","i","o","u"]
    for letter in word:
        try:
            word.remove(letter) == vowels.upper() and word.remove(letter)== vowels.lower()
        except ValueError:
            pass 
        return word

1 Answer

Steven Parker
Steven Parker
231,236 Points

The try itself seems OK. But you do have some other issues:

  • you probably want to iterate through the vowels instead of the word
  • for performing a test, you would use an if statement
  • you can't use a string function (like upper) on a list (like vowels)
  • you can't compare a string (like word) directly to a list (like vowels)
  • if you return from inside the loop, your function will end the very first time in the loop