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 trialGregorio Bernabel
3,412 Pointsi am getting : Hmm, got back letters I wasn't expecting!... any tips people?
def disemvowel(word): vowels = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U") for letter in word: if letter not in vowels: word += letter return word
def disemvowel(word):
vowels = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U")
for letter in word:
if letter not in vowels:
word += letter
return word
2 Answers
Unsubscribed User
6,415 PointsHey Greg,
Your thinking is in the right place, but the letters that you're adding to "word" are just getting tacked on to the end of whatever that word already is. For instance, if the word being passed into the function is "hello," you're returning "helloh" also because the return statement is also at the deepest indent level in the loop. So one loop through, you're already returning the string. An efficient way to go about this is just start a new empty string. We also have to move the return outside the loop. Here's some code that will solve:
def disemvowel(word):
vowels = 'aeiouAEIOU'
new_word = ''
for letter in word:
if letter not in vowels:
new_word += letter # adding letters that aren't vowels to the empty new_word in order
return new_word
Tim Sullivan
1,916 PointsThink about the word variable... It's an arg to your function, and you do some stuff to it, then your function returns it. How has it changed? In other words, where are you removing the vowels from the word variable.
Gregorio Bernabel
3,412 PointsGregorio Bernabel
3,412 Pointsso that's what it was doing. I kind of thought about making another variable and empty strings on it as I was seeing how this is done so I can get a better understanding of how it works and do it. thank you. it worked