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 trialSam Bui
878 Pointsdisemvowel1 challenge issue
Hi, I am doing the disemvowel challenge from Python Collection. The question asks to create a function that remove all vowels (uppercase and lowercase) in a word and then return it.
So I create 2 list of vowels, one is for uppercase letters and the other is for lowercase letters. Then I run a for loop through the input word and if all the letter in that word also in my vowels lists, I will remove it with word.remove(letter).
But at the end, it says I am not correct, I try to look at my code and I really don't see anything off about my code. I would be very appreciate if you can point out what I did wrong.
Thank you
def disemvowel(word):
vowels_lower = ['a','e','u','o','i']
vowels_upper = ['A','E','U','O','I']
for letter in word:
if letter in vowels_lower or letter in vowels_upper:
word.remove(letter)
else:
return word
2 Answers
Josue Ipina
19,212 PointsI believe you can't use the remove method on strings, so first, you'll have to turn word into a list. Then use a for loop to iterate through word, and checking if each letter is contained in 'aeiouAEIOU'. Then proceed to use .remove() and .join() to return as a string. In case i don't explain well enough, here's the code:
def disemvowel(word):
mylist = list(word)
for letter in word:
if letter in 'aeiouAEIOU':
mylist.remove(letter)
return ''.join(mylist)
Sam Bui
878 Pointsoh, that's right, I totally forget that the input is string type and therefore I need to convert it back to list in order to compare. Thank you for remind me