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

How do I check for upper-case and lower-case?

I believe I got most of this right.

But now I can't figure out how to check for both lower-case and upper-case.

Could you please tell me the theory of how to do it without telling me the direct answer :)

disemvowel.py
def disemvowel(word):
    what_to_remove = ["a", "e", "i", "o", "u"]
    try:
        word = word.remove(what_to_remove)
    except ValueError:
        pass
    return word
Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

This is not an answer, but just a hint. Right now you have a list containing all the lower case vowels. Why not add the upper case vowels to that list as well? :smiley:

2 Answers

Steven Parker
Steven Parker
231,269 Points

You can compare both the lower-case and upper-case versions of a character separately as Jennifer suggested. Or if you are performing a comparison with a single letter, you could convert the case of that letter using the Python upper() or lower() functions and then just do a single comparison.

Another hint: it appears you're trying to use a "remove" method on the string "word", but strings do not have a "remove" method. Python strings are actually immutable (cannot be changed). Perhaps you were thinking of converting the string to a list first?

Thanks for the second hint. I'm trying to get it working but for some reason .split() won't get the job done. How would I turn it into a list?

def disemvowel(word):
    word = word.split()
    what_to_remove = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    try:
        word = word.remove(what_to_remove)
    except ValueError:
        pass
    return word
Steven Parker
Steven Parker
231,269 Points

The "split" is probably working just fine. But you can't give "remove" a whole list of things to remove (unless the other list as a sublist that matches it exactly). You might need a loop to remove one at a time.

And don't forget that both the argument and return values are strings, so if you convert to a list, you'll need to convert back before you return it.

Could you give me an example of a loop that'll work? But don't give me a loop that matches the challenge.