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

Kento Nambara
Kento Nambara
1,764 Points

Can somebody explain what is wrong with my code for Challenge 1 of Python Collections?

This code does not work for words with multiple vowels of the same type like "piiiizaaa." Anything would help!

def disemvowel(word):
    word = list(word)
    vowel = ["a", "e", "i", "o", "u"]
    for letter in word:
        if letter.lower() in vowel:
    word = "".join(word)
    return word

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! I can explain it, but it's going to take some time and reading on your part. I left a rather lengthy explanation in a thread a while back along with a rather detailed example. You'll need to scroll all the way down to see the example.

But the short answer is, you're mutating the thing you're iterating over and it's causing some checks to be skipped.

Here you can see the detailed explanation.

Hope this helps! :sparkles:

edited for additional hint

:bulb: Try making a copy of the original list and iterating over that and then remove from the original list :smiley: