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 trialBuck Randall
1,714 PointsWhat's wrong with my code
def disemvowel(word): vowels=['a','e','i','o','u'] char_list=list(word) for letter in char_list: for vowel in vowels: if letter.lower()==vowel.lower() or letter.upper()==vowel.upper(): char_list.remove(letter) word=''.join(char_list) return word
print(disemvowel('watermelon'))
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information.
======================= RESTART: C:\Python27\buck1.py ======================= wtrmln
def disemvowel(word):
vowels=['a','e','i','o','u']
char_list=list(word)
for letter in char_list:
for vowel in vowels:
if letter.lower()==vowel.lower() or letter.upper()==vowel.upper():
char_list.remove(letter)
word=''.join(char_list)
return word
print(disemvowel('watermelon'))
1 Answer
james south
Front End Web Development Techdegree Graduate 33,271 Pointswell one thing is that you are modifying a list that you are looping through. this causes elements in the list to be skipped, and while your code works for watermelon, it doesn't work for any word with consecutive vowels. make a copy of the list, loop through it while modifying the original or vice versa. also you don't really need nested for loops but it can still work. you could also throw in a break statement to reduce unnecessary comparisons.