Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Corinn 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
221,938 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
221,938 PointsSteven Parker
221,938 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!