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 trialPrashant Gaykar
1,144 PointsDidn't get the right values from `reverse_evens`.
I am able to obtain desire result with reverse_evens() on my machine but on treehouse it shows error.
def first_4(mlist):
return mlist[0:4]
def first_and_last_4(mlist):
return mlist[0:4] + mlist[-4:]
def odds(mlist):
return mlist[1::2]
def reverse_evens(mlist):
return mlist[::-2]
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! Yes, your code works, but only in half cases. Notably, it works when the number of elements is odd. So the given the test data [1, 2, 3, 4, 5]
, it will return [5, 3, 1]
. But if we put in [1, 2, 3, 4, 5, 6]
, it will return [6, 4, 2]
, which is not what we would expect. We would still expect to get back [5, 3, 1]
as the even indexes still contain 1, 3, and 5.
You will have to do this a bit differently. First, get all the even indexes, then reverse them.
I think maybe you can get it with this hint, but let me know if you're still stuck!
Prashant Gaykar
1,144 PointsPrashant Gaykar
1,144 Pointsok got that! thanks Jennifer for the help.