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

Add vowels to a function

I actually wonder what is it that i have to do

disemvowel.py
def disemvowel(word):
    vowels = ["a","e","i","o","u"]
    word == vowels
    return word

1 Answer

James Arnold
James Arnold
3,986 Points

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!

def disemvowel(s):
    result = ''

We start by creating a variable 'result' that right now holds an empty string.

def disemvowel(s):
    result = ''
    for letter in s:

We'll then add our for loop to iterate through our provided word or letters coming into the function.

def disemvowel(s):
    result = ''
    for letter in s:
        if letter.lower() not in 'aeiou':
            result += letter
    return result

Then, we'll add our conditional here in our for loop. We'll lowercase our iterator - letter - here by using the .lower() method. If this lowercase letter is not in the string 'aeiou' then we will add the iteration to our result variable we created earlier. We return the result variable and we should have the correct answer!