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

Alan Christensen
Alan Christensen
2,319 Points

disemvowel(word) - unable to complete challenge

Hi guys,

I have tried my code on the console and everything works fine. The code checks for Upper or Lower case vowels (by turning 'word' into lower case) and removes all vowels, even when the same vowel is repeated multiple times in 'word' (with the While condition)

I am unable to complete the challenge though. I get the error Message "I got letter I was not expecting"

Can you guys give a hint ?

Thank you in advance,

Alan

disemvowel.py
def disemvowel(word):
    word = word.lower()
    vowels = ['a','e','i','o','u']
    word_list = list(word)
    for vowel in vowels:
        for letter in word_list:
            while not letter.find(vowel):
                try:
                    word_list.remove(vowel)
                except ValueError:
                    break
            else:
                continue
    word = ''.join(word_list)
    return word

1 Answer

Nathan Tallack
Nathan Tallack
22,160 Points

The challenge question has this hint in it.

Oh, be sure to look for both uppercase and lowercase vowels! So changing it all to lower case is what broke it.

Your code without that change works great.

def disemvowel(word):
    vowels = ['a','e','i','o','u','A','E','I','O','U']
    word_list = list(word)
    for vowel in vowels:
        for letter in word_list:
            while not letter.find(vowel):
                try:
                    word_list.remove(vowel)
                except ValueError:
                    break
            else:
                continue
    word = ''.join(word_list)
    return word

Keep up the great work! :)

Alan Christensen
Alan Christensen
2,319 Points

Thank you, it worked great.

I thought that turning it all to lower case made it easier.