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 trialCam Treschuk
7,378 PointsWhat am i doing wrong
This isn't working. I am trying to use a for loop to go through every letter.
def disemvowel(word):
vowels = 'aeiou'
position = 0
word = word.lower
for letter in word:
if word[position] in vowels:
del word[position]
position += 1
return word
1 Answer
Wesley Trayer
13,812 PointsGood idea, but strings can't have items deleted from them. :)
def disemvowel(word):
vowels = 'aeiou' # You could also include an uppercase of each letter in this string
position = 0
word = word.lower # Remember, you will have to return "word" with letters still uppercased. Here you lowercased them all.
for letter in word:
if word[position] in vowels:
del word[position] # TypeError: 'str' object doesn't support item deletion
position += 1
return word
Because you can't delete letters from a string, I would suggest first making a list that included all the letters, remove the letters from it, then "join" the letters back to a string.
If you need more help just let me know.