Welcome to the Treehouse Community
Looking to learn something new?
Disemvowel: Uncertain why solution does not receive a pass.
I have tested the following in an iPython notebook and appears to work in different test cases for a single word. Can anyone tell me why the solution does not pass the requirement of removing all vowels from a given work (tested for upper and lower case).
def disemvowel(word): word = list(word) vowels = ["a", "e", "i", "o", "u", 'A', 'E', 'I', 'O', 'U'] x = True for letter in word: if letter in vowels: while x == True: try: word.remove(letter) except: break else: continue word = ''.join(word) return word
Christopher ShawPython Web Development Techdegree Graduate 58,236 Points
Unfortunately, you have to rethink your answer.
Test it with:
and you will get back 'eoAIU'.
This is because, as it removes the first 'a', the list shifts left, so the next item is not 'e' as you are expecting, but 'i'.
Rather than iterate the word, iterate the vowels, then use word.remove(vowel) and this will remove all instances of that vowel from the word. Also, there is no need for the try, as there will be no exception if no letter is removed.
Steven Parker216,083 Points
I bet you didn't test it on a word like "boat".
When you iterate on a sequence, and then modify the same sequence inside the loop, you can cause unexpected behavior such as having items skipped over.
Two ways to avoid this are to iterate on a copy of the sequence, or instead of modifying it in the loop, construct a new result instead.
Also, you dont need "x". You can just say "