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 trialJason Chiang
1,085 PointsSlice Functions: Reverse_evens problem
Hi, I am not sure what the issue is with the last step. I made a small if statement to make sure if the last item is an even, then it would start at the second to last item (which should be odd). Then it would return odd numbers backwards, as asked in the problem.
def first_4(items):
return items[:4]
def first_and_last_4(items):
first = items[:4]
last = items[-4:]
both = first + last
return both
def odds(items):
return items[1:999:2]
def reverse_evens(items):
if items[-1] % 2 == 0:
return items[-2::-2]
else:
return items[::-2]
1 Answer
KRIS NIKOLAISEN
54,971 PointsThe list of numbers was just an example. But what if you try ["dog",2,3,4,5,"cat"]? The instructions state the function accepts a single iterable as an argument so that would be valid input. Instead of checking the value of a single item you could check the total number of items to see if it's odd or even.