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 trialJoel Webster
1,303 PointsWhat's wrong with my disemvowel() function?
Seems to work fine in PyCharm but the challenge says it's getting back more letters than it should be?
def disemvowel(word):
# convert word to list
word_list = list(word)
for char in word_list:
if char.lower() in list("aeiou"):
word_list.remove(char)
# convert word_list back to string
word = ''.join(word_list)
return word
1 Answer
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Joel
Don't use the remove function, the reason being, it only removes the first occurrence in the list. See below i amended you code slightly, I reset word to en empty string, appended the letter that is not a vowel to the string word. Also, you dont need to convert the string aeiou to a list.
def disemvowel(word):
# convert word to list
word_list = list(word)
# set word back to an empty string
word = ""
for char in word_list:
if char.lower() in "aeiou":
# if the letter is a vovel then pass
pass
else:
word+=char
# convert word back as a string
return word
Frank Campos
4,175 PointsFrank Campos
4,175 PointsThank you a lot, I have been working on this problem for days. I created one that worked on the Python interpreter but for some reason, it didn't work on Treehouse.
Muchas gracias,