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

Heidi Ulrich
Heidi Ulrich
4,624 Points

Why does this code not pass?

I can't get why this does not pass. It does the trick, whether I return or print the output, it fails to pass. Why?

disemvowel.py
vowels = ['a','e','i','o','u']
uppervowels = [letter.upper() for letter in vowels]

def disemvowel(word):
    consos = []
    for letter in word:
        if letter in vowels or letter in uppervowels:
            continue
        else:
            consos.append(letter)
    output = ''.join(consos)
    return output

while True:
    the_word = input('> ')
    print disemvowel(the_word)

2 Answers

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

Hi there! Your code is just fine and does, in fact, pass the challenge. But the problem here is that while you were testing it, you forgot to remove the bottom part:

If I remove this part, your code passes:

while True:
    the_word = input('> ')
    print disemvowel(the_word)

Remember, in these challenges if they don't ask you to call a function yourself, it's best not to do so. In fact, it's best not to do anything the challenge doesn't explicitly ask for. Even if functional, it can cause the challenge to fail.

Hope this helps! :sparkles:

Heidi Ulrich
Heidi Ulrich
4,624 Points

Thanks! Will remember it.

Christopher Shaw
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 Points

You can also simplify your code as follows:

def disemvowel(word):
    output = ''
    for letter in word:
        if letter.lower() not in vowels:
            output += letter
    return output
Heidi Ulrich
Heidi Ulrich
4,624 Points

Thank you! The letter.lower() part is smart, I did not think about it that way around. It gets rid of the ugly doubling of the vowels list. And so is the mention of vowels not needing to be a list at all... Can't mark this one as best, but it sure is a good eyeopener! I'm all for simplifying code!