Welcome to the Treehouse Community
Looking to learn something new?
Challenge task 4 of the python slices challenge won't let me pass even though the code is correct.
I tried the code in Visiual Studio to make sure it works as intended and it does. For some reason I get an error for the reverse evens function.
Either return list[::-2] or return list[-1::-2] should work, but neither work in the challenge :/
def first_4(list): return list[:4] def first_and_last_4(list): return list[:4] + list[-4:] def odds(list): return list[1::2] def reverse_evens(list): return list[::-2]
Louise St. Germain19,410 Points
You're almost there - the issue is that when you start slicing from the end with the negative numbers, you haven't found out whether the list has an even or odd number of items. The code you have does work if the list provided has an odd number of a items, but everything is off by one if the list has an even number of items. You will need to add a bit more code to reverse_evens to account for the fact that the list could have either an odd or even number of items.
I hope this helps!