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 trialAlwen Nyikadzanzwa
1,541 Pointshow do I remove vowels since I don't know the indexes of the word to be place d in the function?
how do I remove the vowels from the input word
def disemvowel(word):
a = word.lower()
for letter in a:
if letter == "a":
a.remove("a")
elif letter == ("e"):
a.remove("e")
elif letter == ("i"):
a.remove("i")
elif letter == ("o"):
a.remove("o")
elif letter == ("u"):
a.remove("u")
return word
1 Answer
Steven Parker
231,275 PointsThe "remove" function doesn't need an index, but it also does not work on strings. You would need to convert the string to a list to use it, then convert it back later.
But there are other methods that do work on strings that also don't need an index, such as "replace".
But however you go, be aware that modifying an iterable inside the loop it is controlling can cause items to be skipped over. You might want to iterate using a copy of the iterable.