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 trialAgustin Fitipaldi
1,644 Pointsiv'e run this multiple times through the terminal and it returns exactly what the challenge asks for... but nope
ran it through python 2 and 3 and it returned and printed the word without the vowels. The challenge says I can figure it out anyway I want, clearly not?
word = 'astrophysics'
def disemvowel(word):
wordlist = list(word)
for letter in wordlist:
if letter == 'a' or letter == 'A':
while True:
try:
wordlist.remove('a')
except ValueError:
break
while True:
try:
wordlist.remove('A')
except ValueError:
break
elif letter == 'e' or letter == 'E':
while True:
try:
wordlist.remove('e')
except ValueError:
break
while True:
try:
wordlist.remove('E')
except ValueError:
break
elif letter == 'i' or letter == 'I':
while True:
try:
wordlist.remove('i')
except ValueError:
break
while True:
try:
wordlist.remove('I')
except ValueError:
break
elif letter == 'o' or letter == 'O':
while True:
try:
wordlist.remove('o')
except ValueError:
break
while True:
try:
wordlist.remove('O')
except ValueError:
break
elif letter == 'u' or letter == 'U':
while True:
try:
wordlist.remove('u')
except ValueError:
break
while True:
try:
wordlist.remove('U')
except ValueError:
break
word = ''.join(wordlist)
print(word)
return word
disemvowel(word)
1 Answer
thegeorge
3,393 PointsI'm unsure on the error you're getting, but you could try this and tell me how it goes?
word = 'astrophysics'
vowels = ['a', 'e', 'i', 'o', 'u']
def disemvowel(word):
wordlist = []
# Loop through each character in the string.
for character in word:
if not character.lower() in vowels: # If the character is NOT a vowel. (.lower() converts the letter to lowercase)
wordlist.append(character) # Add to our array
# No need to print(word) if we're returning it.
return ''.join(wordlist) # Can return statements in Python
print(disemvowel(word))
Agustin Fitipaldi
1,644 PointsAgustin Fitipaldi
1,644 Pointsoh my, hadnt thought at all about this method... tried it out, and it worked! I need to start developing different ways of solving problems, because my current ones are inefficient lol. thanks again!