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 trialSalman Badshah
1,473 PointsI dont understand what am I doing wrong with the challenge?
So this is my code. I don't know whats wrong but this should work? Can someone please help?
def disemvowel(word):
if word:
try:
word.remove('a') or word.remove('A') or word.remove('e') or word.remove('E') or word.remove('i') or word.remove('I') or word.remove('o') or word.remove('O') or word.remove('u') or word.remove('U')
except ValueError:
pass
return word
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsThe code fails for the following reasons:
- the string passed into
word
does not have aremove
attributes. Instead, create a list out ofword
first. Remember to convert back to a string using thejoin()
method before returningword
- By using series of
or
conditions, the removals will stop on the first vowel not found. Instead, you will need to use a loop check each character in word character list. - Without a loop, repeated vowels would not be removed, only the first occurrence.
Post back if you need more help. Good luck!!
Salman Badshah
1,473 PointsSalman Badshah
1,473 PointsOk so, in the end, do I have to convert my list back to a string before returning it? For your second point you mean to say I need to use a for loop? I am sorry I don't quite understand what or-ed expressions are?
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsYes, you'll need to convert to a list at the start and back to a string at the end. Yes, you will need a loop. By or-ed expressions, I meant a series of
or
conditions.I've corrected my answer to reflect this.