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 trialDezhi Zhu
2,662 PointsPlease help
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]. You can do it!
def first_4(arg):
return(arg[0:4])
def first_and_last_4(arg):
return(arg[:4]+arg[-4:])
def odds(arg):
return(arg[1::2])
def reverse_events(arg):
return(arg[::-2])
2 Answers
Brian Anstett
5,831 PointsHey Dezhi, For what's its worth, you reverse_events() function get the wanted result of [5, 3, 1] but you named it "reverse_events()" instead of "reverse_evens()". The grader is really specific, so change the name and see if that makes it correct.
Good Luck!
Steven Parker
231,236 PointsHere's some hints:
- you wrote "reverse_events" but the function name should be "reverse_evens"
- a simple reverse index will only work on half of the possible cases
- as it is now, getting "evens" or "odds" will be based on the size of the list
- to always get evens, the index will need to be calculated based on the list size
- another approach would be to get evens first, then reverse them in a separate operation