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 trial

Python Python Collections (2016, retired 2019) Slices Slice Functions

Derick Ho
Derick Ho
3,113 Points

Why does the prompter tell me that my solution is incorrect however is reviewed my answer and it returns the correct val

I am having a problem with reverse evens specifically. I am supposed to return a list that is the reversal of the original and only the even indexes of that list. However after i completed the task it tells me it is incorrect.

slices.py
def first_4(whatever):
    return whatever[0:4]

def first_and_last_4(single):

    final = single[0:4]
    final.extend(single[-4:])
    return final

def odds(provided):
    return provided[1::2]

def reverse_evens(single):
    reverse = single[::-1]
    final = []
    for item in reverse:
        if(reverse.index(item) % 2 == 0):
            final.append(item)

    return final

1 Answer

to get a even index on the list u need to advance with 2 steps [0::2] and to reverse it add [-1]

Derick Ho
Derick Ho
3,113 Points

Thank you for your answer, I changed my solution to list[::-2] which will do the specified task but it still tells me it is wrong. I ran my code and it is correct but for some reason the problem won't accept my solution.