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

Henry Lin
Henry Lin
11,636 Points

disemvowel function didn't pass the challenge but worked fine on workspace!

What's wrong with my code? it does the trick that the question describes

disemvowel.py
def disemvowel(word):

    vowels =['a', 'e', 'i', 'o', 'u']
    result = ''
    for letter in word.lower():
        if not letter in vowels:
            result += letter
    word = result
    return word

3 Answers

Ari Misha
Ari Misha
19,323 Points

Hiya Henry! When question said "be sure to look up for both uppe() and lower() cases", it can mean more than one possible statements. But this is how i'd solve this:

def disemvowel(word):

    vowels =['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
    result = ''
    for letter in word:
        if not letter in vowels:
            result += letter
    word = result
    return word
Ryan S
Ryan S
27,276 Points

Hi Henry,

You almost got it, but what happens if "word" contains uppercase letters? Your for loop converts every letter to its lowercase version and stores that in result.

You'll need to find a way to preserve the original case.

Good luck.

Henry Lin
Henry Lin
11,636 Points

Thank you for help, I got it now.

I am also facing a similar challenge. The code is working fine in workspace but I keep getting an error on the challenge. I can see that I am even preserving case of the initial letters.Here is my code:

    def disemvowel(word):
    vowels=["a","e","i","o","u"]
    word_length=len(word)
    index=0
    wordlist=list(word)

    while(index<word_length):
        if wordlist[index].lower() in vowels:
            del wordlist[index]
        index+=1
        word_length=len(wordlist)

    word=''.join(wordlist)
    return word