Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Slices Slice Functions

I think this test is broken

The code I have should work

nums = list(range(0,10))

def first_4(nums):
    return nums[:4]

def first_and_last_4(nums):
    del nums[4:-4]
    return nums

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

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

Question was...

Make a function named reverse_evens that accepts a single iterable as an argument. Return every item in the iterable with an even index...in reverse. For example, with [1, 2, 3, 4, 5] as the input, the function would return [5, 3, 1].

The first few functions were from other questions in the lesson.

2 Answers

Blayne Holland
Blayne Holland
18,817 Points

Maybe I too am missing something but I agree, That should work

Christian Mangeng
Christian Mangeng
15,969 Points

Have to correct myself regarding the order of steps. It works if you first get all the even indexes of the list, and THEN return that list in reversed order. So now it works even if the length of the list is even.

def reverse_evens(it):
    it_new = it[::2]
    return it_new[::-1]