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 trialJoshua Cahoon
7,998 PointsSimpler answer to challenge
I did this prior to watching the challenge answer. Granted, I could move the vowels into a constant, but I was surprised at the unnecessary complexity in the answers that I have seen. Leveraging Python's incredible simplicity is important, I think.
def strip_vowels(word):
new_word = ""
for letter in word:
if letter.lower() not in ['a','e','i','o','u']:
new_word += letter
return new_word.capitalize()
strip_vowels("California")
1 Answer
Kenneth Love
Treehouse Guest TeacherYou don't need the list, you can check for membership in a string.
def strip_vowels(word):
new_word = ''
for letter in word:
if letter.lower() not in 'aeiou':
new_word += letter
return new_word.capitalize()
EDIT: Removed unnecessary stuff here.
Joshua Cahoon
7,998 PointsJoshua Cahoon
7,998 PointsYou are absolutely correct about looping through strings! Didn't even think of that.
The letter.lower() in your code and mine are identical, I don't understand that point your trying to make here (I get why we would change the letter to a known case for testing, else we would need to test the upper case equivalents as well. Neither of us are doing that, however).
As for new_word.capitalize(), your challenge listed as a requirement (at around 5:12 in the video) to return the word capitalized, so I did that.
Thank you for taking the time to respond.
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherIt hasn't been entirely too long since I wrote this challenge for me to remember all that's required for it... No, not at all. :)
Joshua Cahoon
7,998 PointsJoshua Cahoon
7,998 PointsI understand completely. I just want to make sure anyone that looks on doesn't get confused by conflicting information.