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 trialEmil Hejlesen
3,014 Pointshey can any one help me with removing the vowels in the python coding challenge disemvowel.py :)
i need to remove all vowels from a word
def disemvowel(word):
list(word)
for x in word:
if x == "a", "e", "i", "o", "u":
word.remove(x)
word.join()
return word
2 Answers
Kent Åsvang
18,823 PointsBefore asking questions in the treehouse-community you should try to search and see if someone else has asked the question. Then you wouldn't have to wait for an answer:)
Review of you attempt:
def disemvowel(word):
list(word)
for x in word:
if x == "a", "e", "i", "o", "u":
word.remove(x)
word.join()
return word
You have the right idea, but have made a few errors.
list(word) returns the word as a list, but the return value isn't stored anywhere. should be something like: letters = list(word)
if x == "a", "e", "i", "o", "u": this is invalid syntax. If you wan't to use if-statements this way, you have to make one for each letter.
Solution
def disemvowel(word):
""" removes the vowels from a string """
VOWELS = list("aeiou")
word_wo_vowels = ""
for letter in list(word):
if letter in VOWELS:
pass
else:
word_wo_vowels += letter
return word_wo_vowels
Hope this helped some way.
Emil Hejlesen
3,014 Pointshey tried again with this and it still doesn't work
Emil Hejlesen
3,014 PointsI fixed it now, there was an error with the code you posted it didn't take the capitalized letters but i just added them to the list and it worked, thank you :)
Kent Åsvang
18,823 PointsSorry about the error. I am not a paying treehouse-student so I don't have access to the challenge to see all the criteria.
Emil Hejlesen
3,014 Pointsnp thank you for the help :)
Emil Hejlesen
3,014 PointsThank you for the quick answer :) i tried something similar but i didn't work i have also posted this in the comments thank you for the help, much easier to see my mistake now :)
Emil Hejlesen
3,014 PointsEmil Hejlesen
3,014 Pointsi have changed my code to this but it still doesnt work:
def disemvowel(word): word = list(word) for x in word: if x == "a" or x.upper() == "A": word.remove(x)