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!

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

Georgiy Ukhabin
Georgiy Ukhabin
3,937 Points

Why do I get 'Bummer! Try again!', when this code works well locally?

When I locally define the variable 'word' to any word and tell to 'print' the function 'disemvowel(word)' it works without errors and shows me the 'word' without vowels as it should to. But here Treehouse says 'Bummer! Try again!' Why? What else should I add to pass the challenge?

disemvowel.py
def disemvowel(word):
    vowels  = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U")

    for letters in vowels:
        try:
            word.remove(letters)
        except ValueError:
            pass

    return word

try:

 print(disemvowel(["o", "c", "e", "a", "a", "n"]))
Georgiy Ukhabin
Georgiy Ukhabin
3,937 Points

There is still 'Bummer! Try again!'

what i meant was test your code for the above test-case and you'll see your code failing.

So instead of picking alphabets from vowels and removing from the words, pick alphabets from words and remove it using index() if its present in vowels.

Georgiy Ukhabin
Georgiy Ukhabin
3,937 Points

I turned 'word' into a list and as you said I picked alphabets from words, not from vowels. Then I turned 'word' back into a string. And it worked out. Thanks for solving a half of my mistake. Without you, I wouldn't found the second half of this. By the way, do you know how can I vote for your answer to give you points?

1 Answer

I didn't answered, we were commenting. Here is the answer.

try testcase:

 print(disemvowel(["o", "c", "e", "a", "a", "n"]))

what i meant was test your code for the above test-case and you'll see your code failing.

So instead of picking alphabets from vowels and removing from the words, pick alphabets from words and remove it using index() if its present in vowels.