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

Swapnil Paralkar
Swapnil Paralkar
3,359 Points

Python Collections

Most of the solutions i saw the words from the letter were getting appended to a blank list . I am trying to remove letters from the word (mentioned in the argument) . My code not working . Not sure why my code is failing

disemvowel.py
def disemvowel(word):
        my_list =['a','e','i','o','u']
        check_list = list(word)
        new_word =[]
        for name in check_list:
            if name.lower() in my_list:
                check_list.remove(name)
        word1 = ''.join(check_list)
        return word1

1 Answer

Brett McGregor
PLUS
Brett McGregor
Courses Plus Student 1,903 Points

Hi Swapnil,

I also found this a bit tricky.

Someone more experienced than I am can certainly give a better description of the solution to the problem in your code.

But basically, you need to remove() from a copy of check_list not from the original list. Your code is modifying the iterable.

Don't modify the original iterable, make a copy. Hope this helps you!

[MOD: comment changed to answer (again!) - srh]