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

Can I get help with Disemvowel coding challenge

I get this error TypeError: 'in <string>' requires string as left operand, not list

What am I missing I have been at this for hours now.

disemvowel.py
def disemvowel(word):
 vowel=['a', 'e', 'i', 'o', 'u']
 for letter in word:
        if vowel in word:
            word = word.replace(vowel, '')
 return word

1 Answer

Okay so here are some comments for what's wrong with your solution:

def disemvowel(word):
    vowel=['a', 'e', 'i', 'o', 'u']
    for letter in word:
        # Here, you checked to see if the list, vowel, was inside if your word variable
        # Rather, you should take advantage of your loop though word and see if each
        # letter is inside your list of vowels, or your vowel variable
        # Remember for this challenge, you want it to work for upper and lower case variables
        # one way to do this is to use .lower() on your letters you looped through
        # this way, they will all be lower case just like the vowels in your vowel list
        if vowel in word:
            # so here, you want to replace the letter variable with an empty string
            # so word.replace(letter, '')
            word = word.replace(vowel, '')
    return word

Here is a working solution that simply tweaks what you had:

def disemvowel(word):
    vowel=['a', 'e', 'i', 'o', 'u']
    for letter in word:
        if letter.lower() in vowel:
            word = word.replace(letter, '')
    return word

Thank you I will be more detailed next time.