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 trialJulie Maya
14,666 PointsI think my solution is correct. But it doesn't pass the test
This is my solution. I've tried it on Python tutor and the return is correct: http://www.pythontutor.com/
def disemvowel(word):
string = ""
word_list = list(word)
vowel = ["a","e","i","o","u"]
for letter in word_list:
if letter.lower() in vowel:
word_list.remove(letter)
for char in word_list:
string += char
return string
1 Answer
Charlie Gallentine
12,092 PointsI think your code is altering the index of the loop each time it iterates which can cause it to miss letters. Rather than removing vowels from the original words, I would add the consonants directly to your new string:
def disemvowel(word):
string = ""
word_list = list(word)
vowel = ["a","e","i","o","u"]
for letter in word_list:
if letter.lower() not in vowel:
string += letter
for char in word_list:
string += char
return string
This does have the effect of making the second for loop unnecessary, thus:
def disemvowel(word):
string = ""
word_list = list(word)
vowel = ["a","e","i","o","u"]
for letter in word_list:
if letter.lower() not in vowel:
string += letter
return string
Hope that helps
Julie Maya
14,666 PointsJulie Maya
14,666 PointsYou're right. The second one is superfluous. And I should use "not in" instead of "in" to make the code cleaner.
Thank you Charlie