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 trialCorinn Zieglgansberger
2,419 Pointsdisemvowel issue-taking all the letters except the last one
Hi, when I run this code it is only returning the last letter of the string that was the input. I don't understand at all what's going on. Thanks for your help
def disemvowel(word):
exception = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
test = list(word)
for letter in test:
if letter == exception:
test.remove(letter)
new_word = " ".join(letter)
return new_word
1 Answer
Steven Parker
231,275 PointsIf you modify an iterable inside the loop it is controlling, it can throw off the internal indexing and cause items to be skipped over.
Try iterating with a copy of the iterable, so the loop won't be affected when an item is removed.
Corinn Zieglgansberger
2,419 PointsCorinn Zieglgansberger
2,419 PointsIt's only returning the last letter of the string no matter the length. So it's taking out consonants and vowels. Making a copy of it didn't solve the problem. Thanks though
Steven Parker
231,275 PointsSteven Parker
231,275 PointsSorry, I spotted a common issue and just led with that. Here's some hints for each issue:
I'll bet you can get it now, but write again if you still have trouble!