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 trialPerfect Tinotenda Mashingaidze
5,070 PointsDisemvowel can you provide me the perfect code...I'm stack
vowels = ["a", "e", "i", "o", "u"]
def disemvowel(word): word = word.lower() new = "" for letter in word: if letter in vowels: pass else: new += letter
return new
w = raw_input("Enter word: ") print "[INFO] Word without vowel: ", disemvowel(w)
vowels = ["a", "e", "i", "o", " u"]
def disemvowel(word):
word = word.lower():
new = " "
for letter in word:
if letter in vowels:
pass
else:
new += letter
return new
w = raw_input("Enter word: ")
print "(INFO) word without vowel: ",
disemvowel(w)
1 Answer
Philip Schultz
11,437 PointsI see a couple of things. You can declare the vowels list inside the function. Also, you don't want to turn the word into all lowercase letters, you just want to test every lowercase version of each letter. You are changing the state of the word to all lowercase and there is no way to go back and find out what was once uppercase.
Also, when you declared the new string you have an unnecessary space inside it.
See the code below. Notice how I'm using the lower.() function in the if statement. You can read the if statement like this - if the lowercase version of this letter is in the list of vowels, then pass otherwise add the letter to the new string. Note when I do it like this it doesn't change the state of the original letter to lowercase, it just test the lowercase version of the letter.
def disemvowel(word):
vowels = ["a", "e", "i", "o", "u"]
new = ""
for letter in word:
if letter.lower() in vowels:
pass
else:
new += letter
word = new
return word
Let me know if you have questions and I'll try to answer the best I can.