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

Cant get "E" to be accounted when disemvowel("OEe")

Trying to work on assignment to finish function, but everything I try has something off with it. I am not seeing the logic issue with my code below.

def disemvowel(word): word_list = list(word)

vowels = ("aeiou")
cap_vowels = vowels.upper()

vowels_list = list(vowels)
cap_vowels_list = list(cap_vowels)

print(vowels_list)
print(cap_vowels_list)

print(word_list))

for letter in word_list:
    print(letter)
    if letter in vowels_list:
        print(letter)
        word_list.remove(letter)
    elif letter in cap_vowels_list:
        print(letter)
        word_list.remove(letter)

print word_list

disemvowel("OEe")

disemvowel.py
def disemvowel(word):
    return word

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Binu David ! This trips up many who attempt it. You are far from the first! The problem is that you are changing the thing you are iterating over. Every time you use the remove function, the check on the following letter will be skipped. This isn't a problem when the following letter is a consonant, but it is a problem when the following letter is a vowel.

The way to mitigate this is to make a copy of the list. Iterate over the original, and then alter the copy. Once you've removed all the vowels from the copy, you will need to rejoin it to be a string, as that is what the challenge is expecting back.

I think you can get it with this hint, but let me know if you're still stuck! :sparkles:

Hi Jen,

Thanks much, that did the trick.