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 Slice Functions

Derick Ho
Derick Ho
3,113 Points

Why is my answer still wrong?

The solution is correct but it won't let me continue because it tells me that the solution is wrong. although i tested the code and it returns exactly what it is asking for. This problem is specific to the problem of reverse_evens problem

slices.py
def first_4(items):
    return items[:4]

def first_and_last_4(items):
    first = items[:4]

    second = items[-4:]
    first.extend(second)
    return first

def odds(items):
    return items[1::2]

def reverse_evens(items):
    return items[-1::-2]

1 Answer

Steven Parker
Steven Parker
231,236 Points

Your solution might seem correct when tested with "lucky data". It will produce the expected output half of the time.

There's two strategies that will yield correct output in all cases:

  • compute the starting position based on the length (actually even/odd-ness) of the list
  • extract the even indexed items first, and then reverse them in a separate operation

Hint: Either method works when correctly implemented, but the second one might be a bit simpler to do.

Derick Ho
Derick Ho
3,113 Points

Thank You! You were correct.