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

John Fu
John Fu
2,594 Points

Disemvowel exercise try loop

I'm working on the disemvowel exercise. I've been trying to get this work for a while. I'm not sure where I am off:

def disemvowel(word): #define the function word_list = list(word) #convert the word into a list vowels = ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'] #define a list of all vowels to check against for x in vowels: #for each vowel try: word_list.remove(x) #try to remove each vowel except ValueError: #until there are no more vowels pass new_word = "".join(word_list) #join the list back into a string return new_word #print the new string

I think I covered everything but clearly I have not.

disemvowel.py
def disemvowel(word):
    word_list = list(word)
    vowels = ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u']
    for x in vowels:
        try:
            word_list.remove(x)
        except ValueError:
            pass
        new_word = "".join(word_list)
        return new_word

1 Answer

Cheo R
Cheo R
37,150 Points

Your last two lines are indented too far. It returns after the first iteration.

The remove() method, only removes the first match from the string, so examples like 'MAVKaxbma' return 'MAVKaxbma'.

John Fu
John Fu
2,594 Points

Ah yes you are correct. I only have it removing the first instance. I need to force it to keep checking until it hits the ValueError each time it checks for a new letter.