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

Been stuck on this one for a week now, please help.

Here is the body of the question

OK, I need you to finish writing a function for me. The function disemvowel takes a single word as a parameter and then returns that word at the end.

I need you to make it so, inside of the function, all of the vowels ("a", "e", "i", "o", and "u") are removed from the word. Solve this however you want, it's totally up to you!

Oh, be sure to look for both uppercase and lowercase vowels!

disemvowel.py
def disemvowel(word):
    vowel = ["a", "e", "i", "o", "u"]
    if word.upper():
        word.remove(vowel)
    elif word.lower():
        word.remove(vowel)
    return word

1 Answer

Erik Linden
Erik Linden
14,313 Points

There looks like a couple of items in here to do differently. Since word is a string, I don't believe that 'remove' is something that can be called and then passed a list. It should cause an error. Also the condition is just testing the string method of upper and lower.

This might be better is you use a var to hold the return value. Then test every letter in word against the list of vowels. Don't lower the letter except for the testing so that if the return is expected to have an upper then it still will. If the letter isn't in the vowel list pass it to the return var.

Maybe something like this:

def disemvowel(word):
    out = ''
    vowel = ["a", "e", "i", "o", "u"]
    for l in word:
        if l.lower() in vowel:
            continue
        else:
          out+=l
    return out