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

Danny Ford
Danny Ford
2,438 Points

code works in workspace, but not in challenge

As title says. This code works in wordspaces, but when I adjust it for the challenge, it gives me "Bummer! Hmm, got back letters I wasn't expecting!".

Any help much appreciated!

disemvowel.py
def remove_list(letter_list, string):
    word = list(string.lower())
    for item in letter_list:
        word = remove_letter(item, word)
    return word

def remove_letter(target_letter, word_list):
    word = word_list 
    while True:
        try:
            word.remove(target_letter)
        except ValueError:
            break
    return word

def disemvowel(target_word):
    letter_list = list('aeiou')
    new_word = remove_list(letter_list, target_word)
    return ''.join(new_word)

Question: in remove_letter you use a while True statement. wouldn't that theoretically run forever barring a ValueError? Just trying to understand Python as well as I can. Thanks!

1 Answer

Danny Ford
Danny Ford
2,438 Points

Worked it out! The wording of the challenge isn't so specific, but it wants the word return in the original case. I removed the .lower() and added the uppercase vowels to letter_list, and it worked!