Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Lists Disemvowel

Daniel D'luyz
Daniel D'luyz
2,880 Points

This editor does not check correctly the answer

I've tried 3 different solutions and they all work on the workspace, but this editor keeps telling me that the string I am returning contains the vowels.

This is the last solution I tried checking:

disemvowel.py
to_remove = ["a","A","e","E","i","I","o","O","u","U"]
def disemvowel(word):
    while len(to_remove) > 0:
        letter = to_remove[0]
        word = word.replace(letter, '')
        to_remove.remove(letter)
    return word

And before that:

disemvowel.py
to_remove = ["a","A","e","E","i","I","o","O","u","U"]
def disemvowel(word):
    word_list = list(word)
    while len(to_remove) > 0:
        letter = to_remove[0]
        while True:
            try:
                word_list.remove(letter)
            except ValueError:
                to_remove.remove(letter)
                break
    return ''.join(word_list)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Daniel D'luyz ! You're doing terrific and your logic is pretty solid. However, you haven't taken into account what happens when your disemvowel function is run more than once. Because you declared the list holding the vowels outside`of the function, once the function completes that list is no longer filled with vowels. It is, in fact, empty. So the second time that function is run, the vowels will not be removed.

To mitigate this, you can place the declaration of the to_remove list as the first line inside your function. That way, every time the function is run, the vowel list will be reset.

Hope this helps! :sparkles:

Daniel D'luyz
Daniel D'luyz
2,880 Points

You are totally right! Thank you very much!