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

Joseph Ferrero
Joseph Ferrero
1,308 Points

Why is my code not working? I have tried it on my own and it seems to be working fine.

Cant figure out why its not working.

disemvowel.py
vowels = ['a', 'e', 'i', 'o', 'u']
def disemvowel(word):
    word = word.lower()
    word = list(word)
    for letter in vowels:
        if letter in word:
            word.remove(letter)
    return(word)

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You have the right idea. Your code will pass with theses corrections:

:point_right: add uppercase vowels to the vowels list

:point_right: remove statement using lower()

:point_right: flip the for and if object targets. For each letter in the word check if the letter is in the vowels list

:point_right: join() the word list into a string before returning it.

:no_entry: Wait! Try to fix your code using the hints above before looking at the corrected code

:white_check_mark: Here's the corrected code:

vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
def disemvowel(word):
    word = list(word)
    for letter in word[:]:
        if letter in vowels:
            word.remove(letter)
    return "".join(word)
Alex Diaz
Alex Diaz
4,930 Points

Pretty sure if you make your vowels list include both under and uppercase letters, it'll help. The challenge says to make sure to check for upper and lowercase letters :) Saying that, you're not going to need the word = word.lower() line as well. Hope I helped!

Joseph Ferrero
Joseph Ferrero
1,308 Points

That is still not working, ay other ideas?

Joseph Ferrero
Joseph Ferrero
1,308 Points

I know what the problem is, the loop stops once it finds vowel and then misses the same vowel if it comes up again in the word. Any idea how I can do that? I am thinking I need to use "pass" in some way but I tried and it didn't work.