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

Alice Ng
Alice Ng
1,560 Points

PLSSS HELP ME!! can't pass this test.

I'm really not sure how to do this. I need to cheak for both upper case and lower case, then return the string without the vowels.

def disemvowel(word):

word=list(word)

vowel =['a','A','o','O','e','E','i','I','u','U']

for letter in word:

    if letter in vowel:

        word.remove(letter)

''.join(word)

return word

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are close! Two areas to fix:

  • the while loop does not have a condition that will exit the loop so it will never stop
  • the original case of the kept letters needs to be returned. Your code returns the upper() of all characters.
  • use a for loop instead of the 'whileloop,such as,for letter in word[:]:` which make a copy of word to iterate over.
  • compare the letter to a list of vowels, removing the letters matching vowels

Post back if you need more help. Good luck!!!

Alice Ng
Alice Ng
1,560 Points

First thank you very much sir, what you have pointed out was really good. So i did this and i updated on the code pad, but it didnt really work out.

def disemvowel(word):

    word=list(word)

    vowel =['a','A','o','O','e','E','i','I','u','U']

    for letter in word:

        if letter in vowel:

            word.remove(letter)

    return word

[MOD: added ```python formatting]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

You've hit a common error in early python coding: modifying the loop iterable. This causes indexes to be off and skips some iterations. To correct, use slice notation to make a copy:

for letter in word[:]: