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

Jay See
Jay See
6,880 Points

Code works in terminal but TH won't accept. Any ideas?

Hi,

I have run into a problem a few times where I can run my code in terminal yet it won't run here.

Can anyone help to highlight where I am going wrong here?

disemvowel.py
def disemvowel(word):
    word = word.lower()
    word = list(word)
    vowels = ["a", "e", "i", "o", "u"]
    for vowel in vowels:
        if vowel in word:
            word.remove(vowel)
    word = ''.join(word)
        return word

1 Answer

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

Hi there! You're doing great but there are a couple of things going on here. First, your indentation is off for your return line. But the biggest problem here is the data set you're testing. Because you are mutating the iterable you're looping over, some checks are being skipped entirely. Check out what happens if you include this line:

print(disemvowel("Treehouse is awesome"))

What is printed to the screen is: trehse s wesome, which obviously still contains vowels. Also, the original capitalization of the word should remain unchanged. What I would expect to get back is Trhs s wsm.

I once left a rather lengthy explanation about what happens to the indexing when you mutate an iterable you're looping over. Take a look at the explanation and then scroll all the way down for an example in this thread.

Hope this helps! :sparkles:

:bulb: On a side note, just because a piece of code appears to work on your system doesn't mean that it fulfills the requirements of the challenge. Try testing other data sets and try to avoid doing anything not explicitly required by the challenge (such as changing the original casing of the word).

Jay See
Jay See
6,880 Points

Thanks Jennifer,

appreciate the help. I think given the arg was called "word" I took it to literally be just that.

I'll have another crack!