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,969 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!