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

returning items at even index in reverse order

Am getting the following message "Didn't get the right values from reverse_evens."

slices.py
def first_4 (dob):
    #dob = ['1972', '1974', '1975', '1977', '1979','1980', '1984', '1986', '1990', '1995', '1998', '20003','2008']

    return dob[0:4]

def first_and_last_4(iterable):
    new = iterable[:4]
    old = iterable[-4:]
    mix = new + old
    return mix

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

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

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Clainos,

Your reverse_evens is wrong, which is why the checker is saying it is not getting the right values.

The question text gives an example input to your function, [1, 2, 3, 4, 5] and describes the required output (each of the even-indexed values in reverse order): [5, 3, 1].

What does your function return for that input? You should also make sure your function works for even-length lists, such as [1, 2, 3, 4, 5, 6]

This question is a bit sneaky, because after the previous challenges you probably expect that you can solve it with a single slice. But you can't. You have to perform a slice on another slice. Once you realise that you have to slice once then slice that result again, you can use the ideas you've already demonstrated in the previous challenges to solve it.

Cheers Alex