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

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