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

srikanth soma
srikanth soma
1,572 Points

slices

def reverse_evens(something):
    copy_of_something = something[::-1] #reversing 
    return copy_of_something[::2] #returning every second value 

Task is print items at even index values in reverse order

what wrong am I doing here?

slices.py
def first_4(arg):
    arg1 = arg[:4]
    return arg1
def first_and_last_4(something):
    result = something[0:4] + something[-4:]
    return result
def odds(arg):
    result = arg[1::2]
    return result
def reverse_evens(something):
    copy_of_something = something[::-1]
    return copy_of_something[::2]

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Srikanth,

You almost have it. The key to this is in the wording of the challenge. Basically it wants you to return the even indexes in reverse. In other words, get the even indexed items first, then reverse them.

While your code is very close, it is actually doing the opposite. It's reversing the list first and returning the even indexes of that.

Hope this helps.