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 trialmalfred koryor
2,093 Pointsdisemvowel problem
can some please help me out, can't seem to figure out this one. Thanks!
def disemvowel(word):
vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O","U"]
for letter in vowels:
if letter.upper() and letter.lower() in list(word):
word.remove(letter)
return word
2 Answers
Charles Kenney
15,604 PointsMalfred,
You're close but there are two problems. The first one being that remove is not a string method, you should be using the replace method. The second one is, you need to update the value of the word. This was my solution:
def disemvowel(word):
vowels = "AEIOUaeiou"
for char in word:
if char in vowels:
word = word.replace(char, "")
return word
Hope this helps,
Charles
Derek Gella
15,215 PointsCharles, thank you for the references. Let me clarify; I believe the instructor introduced the replace method previously but the specific method was not a major point of focus that I am aware of leading up to the challenge. That is why I was a little awestruck with your solution. Regardless, it is clear that you are a talented programmer. Keep up the good work and thank you for your contributions.
Charles Kenney
15,604 PointsYou're welcome! If only recruiters felt that way, haha. Have a good night!
Derek Gella
15,215 PointsDerek Gella
15,215 Pointswhat's interesting is that the instructor didn't refer to the replace method in the lessons leading up to this challenge. Your version is probably the most simple in terms of code... but I would have never guessed to use the methods you had.
Charles Kenney
15,604 PointsCharles Kenney
15,604 PointsDerek,
My apologies. I didn't know that the remove method was not introduced that early in the course. I actually opted to learn python from books and didn't really complete the treehouse course. I based all of the context of this problem on the instructions.
If you're curious however, the most elegant way to solve this problem would be using regular expressions and anonymous (lambda) functions. It'd look like this:
If you like, you can read about these exciting topics here and here.
Hope you enjoy learning python!