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

OK, I need you to finish writing a function for me. The function disemvowel takes a single word as a parameter and then

What the heck? In Pycharm it is working perfectly. But Treehouse challenge don't accept my solution.

Can you help me,please?

disemvowel.py
def disemvowel(word):
    word = list(word)
    string = ""
    for x in word:
        if x.lower() in ["a","e","i","o","u"]:
            word.remove(x)
        else:
            string += x
    return string

print(disemvowel("george"))

2 Answers

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 this word: "gCCeoriiiiige". you are modifying a list with remove while looping through it. when remove removes the indicated element, it shifts remaining elements to the left. the loop moves on to the original next element however, which results in elements being skipped and not considered by the code at all. so when this happens in your particular implementation, some letters that should fall through to your return string are not doing so.

I got that finally. I removed the list and used string. This task wasn't about deleting items from list, but do new string without "a",etc ... but thanks :)