Slice 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]
The 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.