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

Jake Du
Jake Du
2,369 Points

II'm not sure what I am missing out in my code.

I do know that I have to convert word to a list so that I can iterate through it and remove any vowels. To do this, I make sure that all the letters in word are lower case then run it through a try loop to remove all the vowels.

This is where it gets tricky for me, I am assuming that all the vowels have been removed and in order to form the word again. I know I have to iterate through the list and concatenate each item into a string.

Despite this, I am still not getting the code correct. Need help please!

disemvowel.py
def disemvowel(word):
    mylist = list(word.lower())
    try:
        mylist.remove('a')
        mylist.remove('e')
        mylist.remove('i')
        mylist.remove('o')
        mylist.remove('u')
    except ValueError:
        pass
    for i in mylist:
        word += i
    return word

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Your code will only remove the first occurrence of each vowel and only if all the previous vowels are present in the word. If the word "bob" is submitted, there is no "a" so the try block will exit.

:point_right: Add a loop to check every letter in mylist is a vowel. Think: for each letter in mylist, is it not a vowel, then save it to return.

:warning: Don't modify the iterable being loop over in a for loop.

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