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

Kade Carlson
Kade Carlson
5,928 Points

Still not understanding this very well

Someone else tried answering this for me but I still can't get it

disemvowel.py
def disemvowel(word):
    for letter in word:
        if letter.lower() == 'a' or 'e' or 'i' or 'o' or 'u':
            list(word)
            word.remove(letter)
            ''.join(word)
    return word

1 Answer

bryonlarrance
bryonlarrance
16,414 Points

A couple things that might help.

This site is great for visualizing your code http://pythontutor.com/

Also, you can go the list route, but I think it is a bit more condensed to keep your word as a string.

I created a new_word. Searched for every letter in that word that is NOT in the string 'aeiou'

Then I added or concatenated the letters that are not vowels into my new_word.

def disemvowel(word):
    new_word = ''
    for letter in word:
        if letter.lower() not in 'aeiou':
            new_word += letter
    return new_word

Put this code in python tutor and it might help to see the process in real time.

def disemvowel(word):
    new_word = ''
    for letter in word:
        if letter.lower() not in 'aeiou':
            new_word += letter
    print (new_word)

disemvowel('gCCeoriiiiige')