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 trialEberechukwu Durumbah
80 Pointswhats wrong with my code
on line 6, its showing me errors with tabs
def disemvowel(word):
for letter in word:
if letter == "a" or letter == "e" or letter =="i" or letter == "o" or letter == "u" or letter=="A" or letter == "E" or letter == "I":
word=("").join(word[:word.index(i)]+word[word.index(i)+1:])
elif letter=="O" or letter =="U":
word=("").join(word[:word.index(i)]+word[word.index(i)+1:])
return word
1 Answer
Steven Parker
231,269 PointsI tried it and I get a different error: "NameError: name 'i' is not defined". Your strategy is unusual yet essentially sound, but to get the index you need will require some refactoring of the loop.
You should also be aware that modifying an iterable while it is controlling a loop can cause the loop to skip items. You might need to use a copy of the iterable instead.
Bonus hint: The membership operator ("in") can make your testing much more compact:
if letter in "aeiouAEIOU":