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

Enzie Riddle
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Enzie Riddle
Front End Web Development Techdegree Graduate 19,278 Points

.remove

Here's 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!

What am I doing wrong, and what is the most efficient way to write this code? PLEASE explain in a way that is easy to understand; I am new to this! Thanks.

disemvowel.py
try:
    while True:
        def disemvowel(word):
            vowels = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"]
            word.remove(vowels)
            return word

2 Answers

Mohammad Usman
Mohammad Usman
5,969 Points

Like Steven Parker said , it'll be easier to use ".replace" instead of ".remove". This was my solution to the challange

def disemvowel(word):
    vowels = "aeiouAEIOU"
    new_word = []

    for letter in word:
        if letter not in vowels:
            new_word.append(letter)

    new_word = ''.join(new_word)
    return new_word
Steven Parker
Steven Parker
231,007 Points

Mohammad Usman — It may help to create a better learning experience for the student to give hints or talk about your solution rather than give an explicit code answer for the challenge.

Steven Parker
Steven Parker
231,007 Points

You'll most likely need a loop.

The remove function doesn't take a list (unless you're trying to remove a list from inside a list), so you'll probably want a loop to step through the vowels and remove them one at a time.

It also only removes the first item it finds that matches, so you should account for words that may have more than one of the same letter.

Also, I think remove only works on lists, but you could convert your word into a list and then back again when you're done. Or did you mean to use "replace"?