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 trialLuis Wenus
634 PointsPlease help with the task
This is probably a very bad try but I don't know how to put more characters in the remove command so I had to put many of them. Still doesen't work though. And is it the right thing braking up the word into a list first?
def disemvowel(word):
word_list = list(word)
try:
word_list.remove('a')
word_list.remove('e')
word_list.remove('i')
word_list.remove('u')
word_list.remove('o')
word_list.remove('A')
word_list.remove('E')
word_list.remove('I')
word_list.remove('O')
word_list.remove('U')
except ValueError:
pass
word = ''.join(word_list)
return word
1 Answer
Mustafa Başaran
28,046 PointsI hope this is clear.
def disemvowel(word):
# make the word a list of letters
word = list(word)
# iterate over a list of wovels (both small and capital letters as instructed in the exercise)
for l in ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]:
# remove all instances of l in word with a while loop and remove() function within the for loop
while l in word:
word.remove(l)
# join the elements of the list word back into a string
word = "".join(word)
# return the disemwoveled word
return word