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 trialsai d
64 Pointswhat is the error
what is the error
def disemvowel(word):
v=['a','e',"i","o","u"]
for letters in word.lower:
if letters == v:
word.remove(letters==v)
else:
continue
return word
1 Answer
Stuart McIntosh
Python Web Development Techdegree Graduate 22,874 PointsHi there a few errors above
- you forgot the parentheses around lower
- you then check if a letter is equal to the entire list
- there is no string.remove function in the string class
Here is an answer that I put together, hopefully it makes sense
def disemvowel(word):
new_word = '' #setup string variable to get the result
v=['a','e',"i","o","u"]
for letter in word.lower(): #iterate through the string lower it first
if letter in v: #check if the letter is in teh vowel list
continue # if yes - do nothing with it
else:
new_word += letter #else letter is not a vowel so add it to the result string
return new_word
if __name__ == '__main__':
print(disemvowel('Friday')) #print the return from the disemvowel function
Hi Sai, I just realised that you are in the lists part of python so if you want use remove() you need to do that with the list
here is another version for you.
def disemvowel(word):
word = list(word.lower()) # create a list from word lower all the chars first
v=['a','e',"i","o","u"]
for letter in word: # iterate through the list word
if letter in v: # check if the letter is in teh vowel list
word.remove(letter) # use the list.remove() function to remove the letter
return ''.join(word) # return a joined version of the list (string)
if __name__ == '__main__':
print(disemvowel('Friday')) # print the return from the disemvowel function