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

I don't understand. This answer works in workspaces.

I tried this way:

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

and

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

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

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

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

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

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

This actually had me stumped to but you really have to read into it and consider other sides of the lists going into it.

# Example 1
numbers1 =  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - numbers1 index list

# even_indices = [0,2,4,6,8] which reversed is -> [8,6,4,2,0]
# expected_output = [9, 7, 5, 3, 1]

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

reverse_evens(numbers1) # returns [10, 8, 6, 4, 2]

So is that the right return? Nope. I mean it is "ever other index" but its the wrong items.

HINT You want the even index items first, then you want them in reversed order.

Haha.. yea I figured it out like 10 minutes after posting it. I probably should read directions more. thanks!