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 trialBen Hedgepeth
Python Web Development Techdegree Student 10,287 PointsDisemvowel challenge help
I'm uncertain why my code is not passing this challenge. Guidance as to what must be fixed is appreciated.
def disemvowel(word):
word_characters = list(word)
vowels = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u']
for character in word_characters:
if character in vowels:
word_characters.remove(character)
else:
continue
return ''.join(word_characters)
1 Answer
Chase Stevens
11,056 PointsYou're right -- your code only removes the first instance of each vowel it finds.
Try this out!
def disemvowel(word):
word_characters = list(word)
vowels = ['A', 'a', 'E', 'e', 'I', 'i', 'O', 'o', 'U', 'u']
word_characters = [letter for letter in word_characters if letter not in vowels]
return ''.join(word_characters)
Ben Hedgepeth
Python Web Development Techdegree Student 10,287 PointsBen Hedgepeth
Python Web Development Techdegree Student 10,287 PointsI believe I've figured out the issue. When removing a letter that happens to be a vowel, it shifts characters towards the front of the list while I'm iterating towards the back.