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) Slices sillyCase

I'm getting this awesome error.

Any ideas Mods?

It passes after a couple of submits.

sillycase.py
def sillycase(item):
    item_list = list(item)
    new_list = []
    for i in item_list:
        if item_list.index(i) < len(item_list)-1:
            i.lower()
            new_list.append(i)
        else:
            i.upper()
            new_list.append(i)
    item = ''.join(new_list)
    return item

I personally like this error. After cycling a few times I got this long "answer":
rkbwJhGgItyTmWSPxLECzDQeaoVMBpqilHvcjsUXYnKF;;;rkbwjhggitytmwspxleczdQEAOVMBPQILHVCJSUXYNKF

:D

Hi Julian,

It looks like the challenge tester is running a different test each time and your code happens to pass one of the tests but it's the wrong logic.

I think the error messages are missing a few words so that they make more sense.

The string that comes before the 3 semicolons is probably what your code is producing and what comes after the semicolons is what it's expecting to get. You'll notice that the first half is all lowercase and the 2nd half is all uppercase.

From nekilof's example

rkbwJhGgItyTmWSPxLECzDQeaoVMBpqilHvcjsUXYnKF # This is what it's getting from your code
rkbwjhggitytmwspxleczdQEAOVMBPQILHVCJSUXYNKF # This is the expected result

As Steven mentioned, slicing will make this much easier. And you need some code to figure out the middle index.

You don't have to convert to a list and you won't need any loops.

2 Answers

Steven Parker
Steven Parker
230,995 Points

Bummer! aYnSNivXVCOzjdJcgWBGqflhksZDpy;;;aynsnivxvcozjdjCGWBGQFLHKSZDPY

Now that is indeed "awesome"! You might want to share that awesomeness in a bug report using the Support page.

But it's a fluke that it passes if you keep submitting, as the logic really doesn't perform the intended task. Since you've passed, you can just move on, but if you really want to construct a valid solution to the challenge, I would recommend re-thinking the approach a bit.

In particular, you can make a much more compact function by making use of slices, as introduced in the previous video. Try creating a slice-based solution and see if you can pass the challenge on the first try.

I see, thanks everyone for the responses. This definitely makes much more sense using slicing. I thought I'd share this though cause the output was so wacky.