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 trialPatricia Snyder
5,563 PointsReceived unexpected letters
Hi, The below code worked outside of the challenge but it doesn't work inside. Can someone spot the problem?
Also, what is a cleaner way to do this? There must be a better way than adding try and except for each vowel.
Thank you. Trish
def disemvowel(word):
word = word.lower()
wordstring = []
for i in word:
wordstring.append(i)
for i in wordstring:
try:
wordstring.remove('a')
except ValueError:
pass
try:
wordstring.remove('e')
except ValueError:
pass
try:
wordstring.remove('i')
except ValueError:
pass
try:
wordstring.remove('o')
except ValueError:
pass
try:
wordstring.remove('u')
except ValueError:
pass
return wordstring
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsThere are two issues with the current code:
-
wordstring
needs to be joined back into a single word - The capital letters are not preserved in the returned word. Be mindful of how you are using
lower()
Post back if you need more help. Good luck!!
Patricia Snyder
5,563 PointsPatricia Snyder
5,563 PointsThank you! I got it to work. I also found a better way to solve the problem using the str.replace() method.