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 trialJulian Cardona
Python Web Development Techdegree Student 4,894 Pointsdisemvowel function
HI! Can someone explain to me why this is wrong?
def disemvowel(word): word = word.lower() word = list(word) for letter in word: if 'a' in word: word.remove('a') if 'e' in word: word.remove('e') if 'i' in word: word.remove('i') if 'o' in word: word.remove('o') if 'u' in word: word.remove('u') word = "".join(word) return word
def disemvowel(word):
word = word.lower()
word = list(word)
for letter in word:
if 'a' in word:
word.remove('a')
if 'e' in word:
word.remove('e')
if 'i' in word:
word.remove('i')
if 'o' in word:
word.remove('o')
if 'u' in word:
word.remove('u')
word = "".join(word)
return word
1 Answer
Steven Parker
231,269 PointsAny letter that is not removed (not a vowel) should not be altered. But this function coverts the entire word to lower case.
Try: "disemvowel("UPPERCASE")
" β the result should be "PPRCS
".
Julian Cardona
Python Web Development Techdegree Student 4,894 PointsJulian Cardona
Python Web Development Techdegree Student 4,894 PointsThanks! Steven! I actually just used a bunch of ifs to look for lower case vowels and upper case vowels. Itβs super inefficient but it did the trick
Steven Parker
231,269 PointsSteven Parker
231,269 PointsIf you wanted to make the code more compact, instead of testing individually for each possible vowel, you could test each letter for membership in a string of vowels.