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 trialDavid Pešava
1,212 PointsProblem with solving code challenge - Disemvowel function
Hi there, i have problem to cpmlete the challenge, i tried it in workspace, and there it works. Can you help me please with reviewing my code?
def disemvowel(word):
vowels = ["a", "e", "i", "o","u"]
word = word.lower()
word = list(word)
for letter in word:
if letter in vowels:
word.remove(letter)
word = ''.join(word)
return word
1 Answer
Steve Hunter
57,712 PointsHi David,
I approached this one by looping through the word
parameter and inspecting each letter in turn. I used a for
loop and called the local variable letter
for the sake of clarity. At each iteration, I checked the lowercase version of letter
. If it was not in
a list of lowercase vowels, I added the letter
to an empty string I initialised at the beginning of the method. I called that output
. I return output
after the loop has finished working.
So, the output
is made up of all characters in word
(in the right order) that aren't vowels. The case of the character isn't altered, as required by the challenge, but the lowercase version is used for the comparison.
That all looked like:
def disemvowel(word):
output = ""
for letter in word:
if letter.lower() not in ['a', 'e', 'i', 'o', 'u']:
output += letter
return output
I hope that makes sense.
Steve.
Chris Reilly
12,086 PointsGreat solution, thanks Steve!
Chris
Dario Bahena
10,697 PointsDario Bahena
10,697 PointsIt does not seem too clear to me in the explanation but it seems like the function should return the string passed to it in its original case. so "SomEsTrIng" should return "SmsTrng". Yours looks like it might return "smstrgn" instead.