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

Am I using the disemvowel function right?

If anyone could tell me what I'm doing wrong here, that would be great. I'm not sure if the or in my code would work. Any advice helps! Thank you!

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

1 Answer

Dave Faliskie
Dave Faliskie
17,793 Points

The or will work fine, but your if statement is comparing the entire word to the entire vowels list. Inside your for loop you should use the letter variable instead of the vowels array. That would then have you comparing the whole word to one vowel letter. The line list(word) isn't going to do anything as is, but you could save that to a list like

word_letters = list(word)

That would give you two lists that you could compare letters for.

But there are likely better ways to solve this problem. Maybe look into .replace() and use that in combination with your vowels list.