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

Ashikur Rahman
seal-mask
.a{fill-rule:evenodd;}techdegree
Ashikur Rahman
Python Web Development Techdegree Student 932 Points

Wrote correct code but it's showing error

Hi! I wrote correct code and checked it but it's throwing an error and I can't fix it. could you please help out? Thanks in advance

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

return word

2 Answers

Hi, Ashikur

def disemvowel(word):
    vowel_list = list('aeiou')  #makes a list out of this string of vowels (you don't have to do it this way)
    word_list = list(word)
    good_list = []

    for letter in word_list:
        if letter.lower() not in vowel_list:
            good_list.append(letter)
    word = "".join(good_list)  # joining the list back into a string
    return word
Steven Parker
Steven Parker
230,274 Points

The code may not be as "correct" as you think:

Letters that are not removed should remain unchanged, but your code converts all letters to lower case.

Also, you only need to define the function, you won't need to call it or to print anything.