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

Julian Cardona
seal-mask
.a{fill-rule:evenodd;}techdegree
Julian Cardona
Python Web Development Techdegree Student 4,894 Points

disemvowel function

HI! Can someone explain to me why this is wrong?

def disemvowel(word): word = word.lower() word = list(word) for letter in word: if 'a' in word: word.remove('a') if 'e' in word: word.remove('e') if 'i' in word: word.remove('i') if 'o' in word: word.remove('o') if 'u' in word: word.remove('u') word = "".join(word) return word

disemvowel.py
def disemvowel(word):
    word = word.lower()
    word = list(word)
    for letter in word:
        if 'a' in word:
            word.remove('a')
        if 'e' in word:
            word.remove('e')
        if 'i' in word:
            word.remove('i')
        if 'o' in word:
            word.remove('o')
        if 'u' in word:
            word.remove('u')
    word = "".join(word) 
    return word

1 Answer

Steven Parker
Steven Parker
231,007 Points

Any letter that is not removed (not a vowel) should not be altered. But this function coverts the entire word to lower case.

Try: "disemvowel("UPPERCASE")" β€” the result should be "PPRCS".

Julian Cardona
seal-mask
.a{fill-rule:evenodd;}techdegree
Julian Cardona
Python Web Development Techdegree Student 4,894 Points

Thanks! Steven! I actually just used a bunch of ifs to look for lower case vowels and upper case vowels. It’s super inefficient but it did the trick

Steven Parker
Steven Parker
231,007 Points

If you wanted to make the code more compact, instead of testing individually for each possible vowel, you could test each letter for membership in a string of vowels. :wink: