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 trialAndrew Nguyen
3,032 PointsDisemvowel Challenge
I don't want to add upper case to my vowel tuple. How do I make this check? I've tried writing an if for letter.upper() but can't seem get anything working. Suggestions? https://w.trhou.se/8gqxir92tn
1 Answer
Alexander Davison
65,469 PointsThis:
def disemvowel(word):
vowels = ("a", "e", "i", "o", "u")
new_word_chars = list(word)
for letter in vowels:
while letter in new_word_chars:
new_word_chars.remove(letter)
new_word_chars.remove(letter.upper())
newWord = "".join(new_word_chars)
word = newWord
return word
Doesn't work due to the check in the while loop for only the lowercase letters.
Try instead:
def disemvowel(word):
vowels = ("a", "e", "i", "o", "u")
new_word_chars = list(word)
for letter in vowels:
while letter in new_word_chars:
new_word_chars.remove(letter)
while letter.upper() in new_word_chars:
new_word_chars.remove(letter.upper())
newWord = "".join(new_word_chars)
word = newWord
return word
(By the way, this solution works, but it is more elegant and clean to write:
def disemvowel(string):
return ''.join([letter for letter in string
if letter not in "aeiouAEIOU"])
You can learn about List Comprehensions for more info on this more elaborate, but neater syntax.)