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

Abhishek Dokania
Abhishek Dokania
893 Points

This code worked for me in ipython notebook but not working here

def disemvowel(word): temp_list = [] temp_list.extend(word) for item in temp_list: if item.lower() in ["a", "e", "i", "o", "u"]: temp_list.remove(item) word = "".join(temp_list)
return word

disemvowel.py
def disemvowel(word):
    temp_list = []
    temp_list.extend(word)
    for item in temp_list:
        if item.lower() in ["a", "e", "i", "o", "u"]:
            temp_list.remove(item)
    word = "".join(temp_list)        
    return word

1 Answer

It's still buggy. As a test case try typing in "aaaaaaaaaaa" or some other vowel repeatedly.

When removing elements from a list within a for loop, you are changing the size of the loop. This makes it function differently and thus skips some letters.

Try using a while loop instead.