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 trialAndrei Li
34,475 PointsCompletely lost. Challenge Task 1 of 1.
Can you help with a challenge? Everything looks fine but it's not working. Thank you in advance.
def disemvowel(word):
vowels = ["a", "e", "i", "o", "u"]
position = 0
for letter in list(word):
for vowel in vowels:
if letter == vowel:
list(word).remove(vowel)
position = +1
return word
1 Answer
Wade Williams
24,476 PointsFew things, when using a for loop in python you don't need to keep a "position" variable, so let's remove that. By default a for loop will go through each character of a string, so no need to turn it into a list. We can do this in one loop, so let's get rid of the vowels for loop.
Your code has a lot going on, so let's describe the algorithm then code it up.
- Create a data structure to hold our vowels (Uppercase and Lowercase)
- Create a variable that will hold our result
- Loop through each character in word, if it's not a vowel then add it to our result
- return result
def disemvowel(word):
vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
result = ""
for char in word:
if char not in vowels:
result += char
return result
Andrei Li
34,475 PointsAndrei Li
34,475 PointsThank you! Very interesting construction.