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

Mobe AF
Mobe AF
3,040 Points

Need advice !

Hello ,

Now i am stuck in this challenge and i dont know what i am doing wrong , its says that it didn't get back the right answer . from the output i see that some letters are removed but others not .

disemvowel.py
def disemvowel(word):
    word1 = list(word)
    vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    for letter in vowels:
        if letter in word1:
            word1.remove(letter)
    word2 = "".join(word1)


    return word2

3 Answers

Jakob Hansen
Jakob Hansen
13,746 Points

If we assume your word is: ('eKAAeiRJcJ') we expect to get back KRJcJ, but with your code we get KAeRJcJ. as soon as your code has removed the first incident of a vowel, it no longer checks against that vowel.

You need to check for multiple cases of the same vowel as well :)

A hint, is an if statement the best approach inside the for loop :)?

think about this; as long as "this vowel" is inside the word list -> remove it)

Daniel Marin
Daniel Marin
8,021 Points

Hi Mobe AF , Here's what I did for that test:

def disemvowel(word):
    vowels = "aeiou"
    result = list()

    for letter in word:
        if letter.lower() not in vowels:
            result.append(letter)

    return ''.join(result)

We do a foreach on letters from the word and then we check if the letter is lower and is not a vowel then we append the letter to result.

Also there's another short way. I had to edit this :)

def disemvowel(word):
    return "".join(c for c in word if c.lower() not in 'aeiou')
Mobe AF
Mobe AF
3,040 Points

passed it , thank you guys so much , really appreciated.