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

Corey Buckley
Corey Buckley
1,257 Points

Why does this not work?

I don't understand why this is adding every letter whether it's a vowel or not to the list new_word

disemvowel.py
def disemvowel(word):
    new_word = []
    the_list = list(word)
    for letter in the_list:
        if letter != "A" or "a" or "E" or "e" or "I" or "i" or "O" or "o" or "U" or "u":
            new_word.append(letter)
    print(new_word)

1 Answer

Steven Parker
Steven Parker
231,269 Points

Your test is probably not doing what you are expecting. Instead of comparing "letter" to each literal string, it is cchecking that it is not equal to "A", and then checking the "truthiness" of "a", and then the "truthiness" of "E" ... etc. And since any non-empty string is considered "truthy" by itself, the test always passes.

You could recode that test so each "or" joins a separate check of "letter" to each literal, but that would make it far more verbose. A much more compact way to do what you intended is to use the membership operator ("in") and invert it using "not":

        if letter not in "AaEeIiOoUu":

Also remember to "join" your list back into a string, and return it. You won't need to "print" anything.