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 trialGian Pompilio
10,463 PointsI 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]
2 Answers
Blayne Holland
19,321 PointsMaybe I too am missing something but I agree, That should work
Christian Mangeng
15,970 PointsHave 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]
Gian Pompilio
10,463 PointsGian Pompilio
10,463 PointsQuestion 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.