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 Zieglgansberger2,419 Points
disemvowel 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
Steven Parker221,938 Points
If 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.