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 trialmamadou diene
Python Web Development Techdegree Student 1,971 PointsYou're on fire! Last one and it is, of course, the hardest. Make a function named reverse_evens that accepts a single i
i need pointers in this challenge please
def first_4(treehouse):
return treehouse[0:4]
def first_and_last_4(computer):
return computer[:4] + computer[-4:]
def odds(challenge):
return challenge[1::2]
def reverse_evens(ilovechallenge):
return ilovechallenge[::-2]
1 Answer
Steven Parker
231,269 PointsWell, they do admit this one is tough. But there's basically two strategies you can use, one is to compute the starting position based on the length of the list and then you can use a single slice. The other is to use one slice to get the even indexed items, and another to reverse the list. Either will pass the challenge.
mamadou diene
Python Web Development Techdegree Student 1,971 Pointsmamadou diene
Python Web Development Techdegree Student 1,971 PointsThis is still not passing
def first_4(treehouse): return treehouse[0:4]
def first_and_last_4(computer): return computer[:4] + computer[-4:]
def odds(challenge): return challenge[1::2]
def reverse_evens(ilovechallenge): return ilovechallenge[-1:-14:-2]
Steven Parker
231,269 PointsSteven Parker
231,269 Pointsno single slice with fixed values will work for all possible inputs. You must either compute the starting position or do it with two slices. You might want to take a look at other questions asked about this challenge.