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

Morten Egge
Morten Egge
1,898 Points

Error on disemvowel

keep getting error on my code, it works in console..

def disemvowel(word):
    vowel = 'AEIOU'
    mod_word = ""
    for i, v in enumerate(word.upper()):
        if not v in vowel:
            mod_word += v

    return mod_word

1 Answer

Michael Hulet
Michael Hulet
47,842 Points

In this case, it's a casing issue. The word you return needs to match the case of the word that's passed in. For example, if the function takes the string "no vowels", it expects to get back "n vwls", not "N VWLS". At the beginning of your loop, you're converting the entire word to be uppercase, so when you build mod_word, all the letters will be unconditionally capital. It'd be better if you converted each individual letter to uppercase when you check to see if it's a vowel instead. That way, you can still keep a list of just the uppercase values, and you still have access to the properly-cased value to append to mod_word

Morten Egge
Morten Egge
1,898 Points

Thank you ! I i changed the code to" for i, v.upper()" Worked like a charm.