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 trial

Python Python Collections (2016, retired 2019) Lists Disemvowel

OK, I need you to finish writing a function for me. The function disemvowel takes a single word as a parameter and then

i am not passing this challenge

disemvowel.py
word = "Treehouse"
vowells = ["a", "e", "i", "o", "u"]
final_result = []

def disemvowel(word):
    for letter in word:
        if letter.lower() or letter.upper() not in vowells:
            final_result.append(letter)
        else:
            continue              
        return final_result

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You have the right idea but there a few errors to fix

  • the return statement is indented to far. This causes the function to return after completing the first pass through the for loop
  • final_list is a constructed as a list, but a string is expected. Use "".join() to create the string
  • the challenge checker runs the function many times, but final_list is initialized only once. This causes results from one test to be added to the next test. Move the initialization inside the function
  • the logic of the if condition is not correct. Each side of the or must be complete comparisons. Simply having letter.lower() before the or will return a letter which is always considered "truthy" making the append happen every time. You could add a check for the lowered letter in the vowell list but since letter.upper() will never be found in the vowels list, the full if condition can be reduced to checking whether the lowered lettered is in the list.

Post back if you need more help. Good luck!!!

i did these corrections:

def disemvowel(word):
    word = "treehouse"
    vowells = ["a", "e", "i", "o", "u"]
    final_result = []
    for letter in word:
        if letter.lower() not in vowells:
            final_result.append(letter)
        else:
            continue              
    return final_result"".join()

And here is what i am getting now Bummer! SyntaxError: invalid syntax (disemvowel.py, line 10)

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Almost there. Two more errors:

  • the syntax error in line 10: final_result should be the argument to the join function
  • delete the assignment word = "treehouse" as it overwrites the argument passed into the function.

YOU ARE A GODDD!! Thank you so much