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

Nikki Wong
Nikki Wong
9,066 Points

I have ensured that all letters are small before I check..

So where am I going wrong? I loop through every letter in the word and I remove the original letter that is contaiend in vowels...What am I doing wrong?

disemvowel.py
def disemvowel(word):

    vowels = ["a", "e", "i", "o", "u"]
    wordList = list(word)
    for letter in wordList:
        letterEdit = letter.lower()
        if letterEdit in vowels:
            wordList.remove(letter)
    result = ("").join(wordList)
    return result

1 Answer

You are iterating AND changing the iterable at the same time! So every time you remove an element from the list, your loop gets shortened...

Simply change to

for letter in list(word):
...

will do.

P.S. this challenge can be done in one line : D

def disemvowel(word): return "".join(list(filter(lambda x: x if x.lower() not in "aeiou" else "", word)))
Nikki Wong
Nikki Wong
9,066 Points

Ah ok!!! I completely missed that one!! Thank you!