Welcome to the Treehouse Community
Looking to learn something new?
Raiyan Ahmad3,622 Points
def disemvowel(word): word.lower() while True: try: word.remove('a', 'e', 'i', 'o', 'u') except ValueError: break return word
vowels[i]? Why? Looping over the
And, to complete this task, you are better off adding to an output list/string letters that aren't a vowel. i.e.
not in vowels. If you start removing from an iterable you are looping over, you get nasty consequences of skipping indexes.
Start by declaring your list of vowels. Create an empty string to output. Iterate over
word. At each iteration see if the letter is not in the list of vowels. If not, add to output. Else, carry on. Return the output string after the loop.
This looks like:
def disemvowel(word): vowels = ['a', 'e', 'i', 'o', 'u'] output = "" for letter in word: if letter.lower() not in vowels: output += letter return output
for loop issue; have a read of this which covers it off.
Rich Zimmerman24,063 Points
You can only remove one item at a time this way with the remove() method. You can try looping through a list of the letters you want to remove. Or loop through the letters in the word and checking if the letter is in the list of vowels and remove it.