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

The last task won't work, why?

The rest of the tasks passed, but the last one just says 'Didn't get the right value from reverse_evens'. I even tested it in the workspace and it worked there.

def first_4(listt):
    return listt[:4]
def first_and_last_4(listt):
    one = first_4(listt)
    return one
def odds(listt):
    return listt[1::2]
def reverse_evens(listt):
    return listt[-1::-2]

2 Answers

Your function reverse_evens doesn't work in all cases. You must take a two-step process: first get the evens; then reverse it.


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

Thanks, it worked!

Adam Paciorek
Adam Paciorek
3,181 Points

any ideas why this does not pass?

My function is :

def reverse_evens(list):
    reversed_list = list[::-1]
    return reversed_list[::2]

You need to first get the even-indexed elements, then reverse it. They aren't the same, they sometimes return different results!