Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Lists Disemvowel

whats wrong

compared each character converted to lower if existed upper then removed vowels

but still not working

def disemvowel(word):
    for i in word :
        if (i == 'a' or i == 'e' or i == 'o' or i == 'i' or i == 'u').lower():
            return word

1 Answer

Stuart Wright
Stuart Wright
41,103 Points

There are a few issues with your code:

if (i == 'a' or i == 'e' or i == 'o' or i == 'i' or i == 'u').lower():

You can't call the .lower() method on a whole expression like that. You can only call it on a string.


In the above line you have tried to remove a letter from a string. You can't do this because strings are immutable. Instead of trying to change the string in place, which can't be done, you could maybe create a new blank string at the start of your function and add to it throughout the loop when you have confirmed that each letter isn't a vowel.

Finally, notice the indentation of your return statement. You need to return after the entire loop has completed, not inside it.

Hopefully this is enough to give you some ideas. Let me know if you need any more help.