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

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: