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

sandeep krishnappa
sandeep krishnappa
1,571 Points

Hi, I tried this code in workspace and it worked out ok. But here it is not. The reply was there are unexpected word.

What is the unexpected word here?

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

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

try it with a word with consecutive vowels like beauty. you will get vowels in the return because you are modifying a list while looping through it. when you call remove, it removes the indicated element and shifts remaining elements to the left. the loop moves on to the original next element however, which skips the first element shifted left. thus the skipped elements do not get evaluated and fall through to the return. to fix you can make a copy of the list and loop through that while modifying the original, or vice versa.

sandeep krishnappa
sandeep krishnappa
1,571 Points

Thanks James. I changed the 'for letter in my_list' to 'for letter in my word' and it passed the checking.