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

What is going on?

I don't understand how my code is wrong. Reverse_evens works in workspaces and everywhere else I can test it. I'm crazy annoyed right now and would like to move on to the next video

def first_4(thing):
    return thing[0:4]

def first_and_last_4(thing):
    return thing[0:4]+thing[-4:]

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

def reverse_evens(thing):
    return thing[::-2]

2 Answers

Why is this correct? This double slice was not covered in any of the material unless I missed it. If so please link to the section where it explains this or freaking change the question to be in the scope of the videos.

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

I've taken this course in the past, and don't remember that being the answer at all. Parallel universes confirmed :D

Renato Guzman
Renato Guzman
51,425 Points

The challenge says it has to return even indexes in reverse. Imagine this list: [1, 2, 3, 4]. The answer is [1, 3]. Because 1 has the index 0, and 3 has index of 2.

  1. Following your first code, the answer will be [4, 2] which is wrong. 4 has index of 3 and 2 has the index 1. These are odd indexes.

  2. The second code you follow first made a list with even indexes and then you reversed it which is correct.

Hope this helps!