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 trialRakshit H Ravishankar
1,309 Pointsdisemvowel.py not working
def disemvowel(word): word=list(word) for it in word: if( it=='a' or it=='A' or it=='e' or it=='E' or it=='i' or it=='I' or it=='o' or it=='O' or it=='u' or it=='U'): try: word.remove(it) except ValueError: pass word = ','.join(word) return word
This is the script I am using. But this is not passing the test. It is throwing an error saying that 'got some vowels back' Can anyone help me here?
def disemvowel(word):
word=list(word)
for it in word:
if( it=='a' or it=='A' or it=='e' or it=='E' or it=='i' or it=='I' or it=='o' or it=='O' or it=='u' or it=='U'):
try:
word.remove(it)
except ValueError:
pass
word = ','.join(word)
return word
1 Answer
Alexander Davison
65,469 PointsYou might be over-thinking this challenge.
It seems that you make this code DRY-er (DRY stands for Don't Repeat Yourself) by using the in
keyword:
def disemvowel(word):
result = ''
for letter in word:
if letter.lower() not in 'aeiou':
result += letter
return result
Good luck! ~Alex
Questions? Please ask below