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!
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 trial
What is wrong with this code?
What is wrong with my code?
def disemvowel(word): char_list = list(word) char_remove = set(('a','e','i','o','u')) for char in char_list: if char.lower() in char_remove: char_list.remove(char) word = ''.join(char_list) return word
Dave StSomeWhere19,870 Points
The issue is that your are looping through a list and modifying that list while in the loop, so it is messing up the loop when you remove a character. It will skip the next character after a remove because you modified which character is at the next index entry value.
Probably the easiest fix is to just loop over
word (of course there are zillions of other options)...
Please let me know if you need additional explanation.
Yes I've got it now, it works.
Thanks a lot Dave.