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 trialJuan Davin
2,792 PointsDisemvowel
This code runs well in workspaces but I cant seem to get it correct
def disemvowel(word):
new=list(word)
for l in new:
if l.lower()=='a':
new.remove(l)
elif l.lower()=='e':
new.remove(l)
elif l.lower()=='i' :
new.remove(l)
elif l.lower()=='o':
new.remove(l)
elif l.lower()=='u':
new.remove(l)
else:
break
so=''.join(new)
return so
2 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou are modifying a list while looping through it. when you call remove, it removes the indicated element, then shifts remaining elements to the left. the loop moves on to the next element however, which means elements will get skipped. to fix you can make a copy and loop through that while modifying the original, or vice versa. when this code is run on a word with multiple consecutive vowels, some vowels slip through, because they are being skipped over.
aaronbuckles
3,291 PointsI know this isn't really answering your question, but to simplify your code a bit you could make a list of vowels like vowels = ['a', 'e', 'i', 'o', 'u']
. Then you could check if letter in vowels
in order to check if the letter is a vowel. This may make it a little easier for you to debug your code.
Juan Davin
2,792 PointsJuan Davin
2,792 Pointsohh i see thank you