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

Am I doing this right?

Hi guys this it my 4th trial to solve this problem, I just don't know how to solve it, please share with me the way you solved it

disemvowel.py
def disemvowel(word):

    vowels_to_remove = ["a", "e", "i", "o", "u"]
    vowels_to_remove_upper = vowels_to_remove.upper()
    word = "string"

    index = 0
    letter = word[index]
    letter_upper = letter.upper()

    for letter_upper in vowels_to_remove_upper:
            word.del(letter)
        index += 1


    return word

1 Answer

Steven Parker
Steven Parker
231,007 Points

Perhaps some more specific hints will help.

Treehouse discourages giving explicit answers to course questions and challenges. But it will give you a better learning experience if we can help you to solve it yourself.

Perhaps my previous hints were a bit terse, I'll elaborate a bit this time and go line-by-line:

    vowels_to_remove = ["a", "e", "i", "o", "u"]
    vowels_to_remove_upper = vowels_to_remove.upper()

Lists don't have an "upper" method, but you could store your vowels in a string instead of a list, since strings are also iterable. Then this would work.

    word = "string"

You don't want to do this — you need to keep word, it was passed in for you to remove the vowels from. Doing this would wipe out the original content and replace it with the word "string".

    index = 0

You probably won't need this, There are better ways to manage a loop.

    letter = word[index]

This won't help much since it is not in a loop. And if you construct a list to iterate over word directly, it will do this for you. For example: "for letter in word:"

    letter_upper = letter.upper()

This doesn't do anything useful, because your loop on the next line is going to replace letter_upper anyway.

    for letter_upper in vowels_to_remove_upper:

It might be less confusing to name this item "vowel_upper", since you use "letter" to refer to parts of the word.

            word.del(letter)

Strings don't have a "del" method. Perhaps you were intending to use "replace"? Or perhaps you had intended to convert "word" into a list before the loop like you did last time. But in that case, lists do not have a "del" method either. For a list you might use "remove".

Also, your loop variable (until/unless you rename it) is letter_upper, not letter. But what if the original letter is lower case? You might need an extra line to handle those.

        index += 1

You won't need this if you make a loop like I talked about above.

Hopefully these hints will help get you back on track.