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

Magnus Jönsson
Magnus Jönsson
1,155 Points

Disemvowel failing challenge, but code works in shell

I am running the code in the python-shell, and it works. But i dont pass the challenge and i can not find what i am doing wrong. Creating an empty list to store the characters that are not vowels in, and then join it at the end. Please any kick in the right direction would be very helpful.

vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
characters = []


def disemvowel(word):
    for character in word:
        if character in vowels:
            pass
        else:
            characters.append(character)

    word = ''.join(characters)
    return word

2 Answers

I'm going to go out on a limb here and say that the Challenge passes in some interesting edge cases that I'm not thinking of or is expecting a few very specific ways to accomplish the task. You are right in that your code seems to work, however, the Challenge seems not to like the way you are building and then recombining an array to a string. Since you technically solved it (as far as I can tell), I'll just offer up another solution that will actually pass the challenge, but in a slightly different way.

def disemvowel(word):
    result = ''        # empty string
    for character in word:
        if character not in vowels:        # there really isn't much need to if/else in this situation
            result += character        # add the character to the string
    return result
Magnus Jönsson
Magnus Jönsson
1,155 Points

Hi Mike Thanks for the quick answer, that was fast :-) And i think i am going to modify my code to match your suggestion and just keep in my mind that there is more than one solution to a problem. Again, thanks for the help Magnus

Magnus Jönsson - Glad to help. I've run into quite a few issues where a certain Challenge didn't like the way I solved it. The beautiful thing about writing code is that it's just as much an art form as it is a literal science, so any problem you have can usually be solved in any number of countless ways. I'm just gonna drop this here: DidSomeoneSayFibonacci?.jpg