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

why its not runnnig properly

def disemvowel(word): word_as_list=list(word) for letter in word_as_list: character=letter.lower() if character in vowels: word_as_list.remove(letter) word=''.join(word_as_list) return word

disemvowel.py
vowels=['a','e','i','o','u','A','I','E','O','U']
def disemvowel(word):
    word_as_list=list(word)
    for letter in word_as_list:
        if letter in vowels:
            word_as_list.remove(letter)
    word=''.join(word_as_list)
    return word

1 Answer

Steven Parker
Steven Parker
216,148 Points

If you remove elements from an iterable while it is controlling a loop, it can cause other elements to be skipped over. You could use a copy of the list for iteration, but an even easeir fix would be to use the original word as the loop iterable while you work on the list.