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

Jui Chi Lee
Jui Chi Lee
969 Points

What is wrong with my code

I returned something weird with my code. For example, should return 'KrSxkTtN' but I got back 'GxBKrSxkTtN'.

disemvowel.py
problem = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
newWord = []
def disemvowel(word):
    for x in word:
        if x not in problem:
            newWord.append(x)
    string = ''.join(newWord)
    return string
Philip Schultz
Philip Schultz
11,437 Points

I'm not sure why this isn't working. I ran the code on pycharm and got back the correct answer. However, when I put your code in the challenge it did error out. I got back the result "Hmm, got back letters I wasn't expecting! Called disemvowel('WOiyYTfwQ') and expected 'WyYTfwQ'. Got back 'PGKDDqzRWyYTfwQ ". I don't understand how it could return more letters than was put in. lol. I'm interested to see if someone finds an answer. Sorry I couldn't help.

1 Answer

Philip Schultz
Philip Schultz
11,437 Points

Actually I figured it out. Just declare 'problem' and 'newWord' within the function. I still don't understand why it worked on pycharm for me though. I would be interested to know and would appreciate it if anyone could explain why there was different outputs.

Philip Schultz
Philip Schultz
11,437 Points

Also, you should not use camelCase when making variables in python. You should change newWord to new_word. It will still work the way you have it, but it is frowned upon in the python community. (from what I hear, I'm new also.)

Jui Chi Lee
Jui Chi Lee
969 Points

Oh, you are so kind, I'm very appreciated your answer. I will take your advice not to use camelCase.