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

Evan Cruz
Evan Cruz
1,090 Points

code challenge: slice function task 4

shouldn't the answer for task 4 be - def reverse_evens(items): return items[::-1][::2]

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

cause I did it in the workspace example and it worked as - numbers[::-1][::2]

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

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

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

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

1 Answer

K.D. Harris
K.D. Harris
11,223 Points

i think it's because of the order in which things are done - for the reverse_even function I did:

    return items[::2][::-1]

this will give you the even-indexed items in reverse order.

using the steps in the opposite order returns something different, though:

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

^that will return all of the odd-indexed items in reverse order.