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

whats wrong

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

but still not working

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

1 Answer

Stuart Wright
Stuart Wright
41,120 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.

word.remove(i)

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.