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

Why is this not accepted?

Disemvowel.py says quote 'solve anyway you want'. This code produces and returns the results from the question when run in workspaces, but does not work in question work area. All the answers that are given in the forum that do work, have very little to do with the video lessons that proceed the challenge - Are we not suppose to use the skills in the videos, i.e. .remove()? Sure there are lots of ways, probably more efficient, to solve this problem but they should all be accepted no?

disemvowel.py
def disemvowel(word):

    new_word = list(word)
    vowel = ('a', 'e', 'i', 'o', 'u')

    try:
        for letter in word:
            if letter == letter in vowel:
                new_word.remove(letter)
                new_word.remove(letter.upper())
    except:
        ValueError
        pass

    word = ''.join(new_word)
    return word

1 Answer

The challenges are a bit strange as they may only accept certain ways. Your code seems to correct but it may not be accepted as treehouse tests may only accept certain ways of doing the programming. But sometimes treehouse like to remind you of the other lessons you have done to try and refresh your memory. Just because you have watched a lesson before the test, it doesn't necessarily it will be on the test. I'm not sure if treehouse does this on purpose or by accident as I have come across this many times especially in some of the JS courses. I know your frustration as these incidents confuse me.

This is the code I produced that:

def disemvowel(s): result = '' for letter in s: if letter.lower() not in 'aeiou': result += letter return result How this works:

We make the function and set a variable called result to an empty string - this is good for later when add letters onto the string (or "growing" the string) then loop through all the letters in the string passed in to the function. If the current letter lowercased is not in 'aeiou', it will then make the string larger. After the loop is over it will return the completed string.

:)