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 trialRafic Faraj
Python Web Development Techdegree Student 1,374 PointsI Dont know what is wrong with my code
the question is this
word = "PIZZA"
def disemvowel(word):
vowel = ["a" , "e" ,"i" , "o" , "u","A" , "E" ,"I" , "O" , "U"]
words = word
if len(words):
try:
words.remove(vowel)
except ValueError:
pass
return words
1 Answer
Owen Orsetti
19,102 PointsHey,
Your "vowel" variable is set to your list of vowels. You probably need to iterate through the list to attempt to remove each specific vowel from your word. Right now you are telling python to remove the entire list from your word.
Also, you can't call "remove" on a string, so you would need to convert your word into a list first using "list(words)", then loop through your vowels and attempt to remove each.
Finally, if you first shifted your word into all lower (.lower()) or all upper (.upper()) case, you would only need to have 1 set of vowels in your list, making it a bit shorter.
Hope that helps
edit: You could try something like this:
def disemvowel(word):
vowel = ["a", "e", "i", "o", "u"]
words = word
if len(words):
word_string = list(words)
for letter in word_string:
if letter.lower() in vowel:
word_string.remove(letter)
return ''.join(word_string)