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

Possible bug in Python Collections Challenge task 4 of 4

Here is the code I submitted with a test based on the problem specification. It appears to be working correctly, but is not accepted.

def reverse_evens(it): rev = it[::-1] eve = rev[0::2] return(eve) l = [1, 2, 3, 4, 5] reverse_evens(l) [5, 3, 1]

slices.py
def first_4(it):
    slice = it[:4]
    return(slice)
def first_and_last_4(it):
    slice1 = it[:4]
    slice2 = it[-4:]
    return(slice1 + slice2)
def odds(it):
    sliceo = it[1::2]
    return(sliceo)
def reverse_evens(it):
    rev = it[::-1]
    eve = rev[0::2]
    return(eve)
Venkat SOMALARAJU
Venkat SOMALARAJU
2,448 Points

True, tried for 72 hours with this code, couldn't avoid "Bummer!" :)

followed below answer, and it works. Don't understand what's wrong with our approach.

1 Answer

def reverse_evens(it):
    eve = it[::2] # remove the odd index
    rev = eve[::-1] # reverse the even index
    return(rev)

Thanks, reversing the two steps did the trick.