Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Lists Disemvowel

Ive tried disemvowel a few different ways, any tips?

I'm trying to use a function to take all the vowels, capital and lowercase, out of a randomly generated word. I understand that .remove only looks for the first instance, so if there are repeated letters it won't remove them. Any tips?

disemvowel.py
def disemvowel(word):
    for letter in word:
        letter.remove("a", "e", "i", "o", "u", "A", "E", "I", "O", "U")
    return word

1 Answer

Heather Malloch
Heather Malloch
2,141 Points

I can't remember how I solved this one, probably from a lot of community googeling!

Make a list of vowels first:

Vowels = ['a', 'e', 'i', 'o', 'u']

Its looks like you need to turn your word into a list:

letters = list(word)

Now you need to loop through your word to find vowels, dont forget to letter.lower

Now because your word is a list you can use letters.remove(letter)

Then work out a way of joining the word back together in the return