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 trialMichael Gallego
1,568 PointsStuck on this challenge. Don't know how to delete all occurrences of the vowel.
If anyone can help me out on this problem, that would be great. Thanks.
def disemvowel(word):
vowels = ["a", "e", "i", "o", "u"]
word = word.lower()
list_of_word = list(word)
for x in vowels:
try:
list_of_word.remove(x)
except ValueError:
continue
else:
print(list_of_word)
word = "".join(list_of_word)
return word
1 Answer
Oszkár Fehér
Treehouse Project ReviewerHi Micheal Your code contains everything to pass but somethings are unnecessary ex.
list_of_word = list(word)
The word,string by default it's a list instead we can create an empty list
list_of_word = []
The word argument shouldn't be changed ex.
word = word.lower()
The try method it's not needed for this quiz. The for loop should actually loop trough the word argument, like so:
for x in word:
Now after this you should check if the x variable it's not in the vowels list
for x in word:
if x.lower() not in vowels: <--- now it should be lowered to match with the "vowels" list --->
From here it's clear that if it's not in vowels it must go in the empty list
for x in word:
if x.lower() not in vowels:
list_of_word.append(x) <---- without the lower() method to actually return the original letter --->
word = ''.join(list_of_word
return word
Or you could return the joined list without setting to a variable
return ''.join(list_of_word)
I hope it will help you out.Happy coding