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

Won't turn string into list

I have tried this code in workspaces and if I put the word = list(word) outside the scope of the function it works perfectly fine. I printed word right before return, and it has the expected result, but upon returning word it subverts back to a string with all the vowels. I am baffled.

disemvowel.py
def disemvowel(word):
    word = list(word)
    vowels = ['A','E','I','O','U','a','e','i','o','u']
    i = 0
    while (i != len(word)):
        letter = word[i]
        if letter in vowels:
            del word[i]
        else:
            i+=1
    return word

1 Answer

AJ Salmon
AJ Salmon
5,675 Points

This is a very interesting way to solve this challenge. Not how I would have done it, but it works like a charm, so well done. :) Your code does turn the string into a list; the issue is that it needs to return a string, not a list. Just join() word and it will pass the challenge!

Thank you!