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

Ben Thrower
Ben Thrower
1,760 Points

Dismevowel

What am I missing?

disemvowel.py
def disemvowel(word):
    vowel = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"]
    word = list(word)    
    for letter in word:
        if letter == vowel:
            word.remove(letter)

    word = "".join(word)
    return word


# I also did a try except but it kept leaving off consanants after the last vowel
'''     try:
            word.remove(vowel)
        except AttributeError:
            word = str(word)
            continue'''

#And this



'''def disemvowel(word):
    vowel = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"]
    for vowel in word:
        if vowel in word:
            word.replace(vowel,"")



    return word'''

1 Answer

The obvious thing is that you saying

if letter == vowel:

But letter is a single letter, while vowel is a list of letters. How could they ever be the same? I think you want to check if letter is in the list that is in vowel. Can you think of a way to do that?

Another potential problem is that you are looping through the letters in "word", but at the same time, you are actually modifying the contents of word, and actually removing parts of it. If you think about it, that is likely to cause trouble, the computer may get confused. It might be better to build a new word, without the vowels, and return that.