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

Reverse_evens isn't working?

I've tried both def reverse_evens(it): return (it[::-2]) and I've tried both def reverse_evens(it): return (it[::-2])

and

return (it[-1::-2])

Both work in repl, so why not here?

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

def first_and_last_4(it):
    return (it[:4] + it[-4:])

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

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Sarah,

You're on the right track, but you're not taking into account the length of the list. If it works in the repl, I'm assuming you're just testing with a list that has an odd number of values, but what happens if you have a list that has an even number of values?

Check out this post for the same question. Logan R gives an excellent example and explanation.

The rest looks great :thumbsup:

Keep Coding! :) :dizzy: