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

i was't able to figure out the disemvowel challenge question

I tried this but it always misses one vowel

disemvowel.py
def disemvowel(word):
    word=list(word)
    n=0 
    for letter in word:
        if (len(word)+10)-n>0:        
            if letter=='a':
                word.remove('a')
            elif letter=='e':
                word.remove('e')
            elif letter=='i':
                word.remove('i')
            elif letter=='o':
                word.remove('o')
            elif letter=='u':
                word.remove('u')
            elif letter=='A':
                word.remove('A')
            elif letter=='E':
                word.remove('E')
            elif letter=='I':
                word.remove('I')
            elif letter=='O':
                word.remove('O')
            elif letter=='U':
                word.remove('U')
        else:                
            n+=1    
    return "".join(word)

1 Answer

Steven Parker
Steven Parker
231,269 Points

If you modify an iterable while it is controlling a loop, it can cause items to get skipped over by the loop. To prevent this, use a copy of the iterable to control the loop.

Also, it shouldn't be necessary to perform any tests on the length of the word.

You are right, I remember it was mentioned in the python basics course, I have to go back and review somethings. I am a beginner.