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 trialIan Cole
454 PointsThe slice function works, but doesn't work
I hammered out this piece and it all works except the last function, "reverse_evens". It tells me it's not returning the proper value. So I took it to my interpreter and... The output is perfect. It's exactly what it should be.
def first_4(itr):
return itr[:4]
def first_and_last_4(itr):
first_4 = itr[:4]
last_4 = itr[-4:]
first_and_last_4 = first_4 + last_4
return first_and_last_4
def odds(itr):
return itr[1::2]
def reverse_evens(itr):
reverse_evens = itr[-1::-2]
return reverse_evens
1 Answer
prateekparekh
12,895 PointsYour solution for reverse_evens() would only work for certain inputs. Can you think of an input for which it will fail? Are you assuming the input to be of a specific size?
Can you divide the final task into 2 components rather than trying to achieve it all in one step?
Here's a hint: 1) Get all the even indexed values 2) Reverse the result from step 1 3) Return this reversed list
Let me know if need help with this. By the way, there's a neat little trick you can use with slices to reverse any list.
Ian Cole
454 PointsIan Cole
454 PointsDamn you're good, thanks for the help!