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

Juan Zevallos
Juan Zevallos
1,401 Points

reverse_evens() function is working in PyCharms but I'm getting the wrong result here - what result am I getting?

This reverse_evens() function code works in PyCharms as expected but I'm not getting the expected results here. It would help if it showed me the result it's actually getting.

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

def first_and_last_4(alist):
    alist = alist[:4] + alist[-4:]
    return alist

def odds(alist):
    odd_list = alist[1::2]
    return odd_list

def reverse_evens(alist):
    alist_reverse = alist[::-1]
    even_list = alist_reverse[0::2]
    return even_list

2 Answers

Juan Zevallos
Juan Zevallos
1,401 Points

Figured it out. I'm NOT supposed to give the even indexes AFTER reversing the list. I just need to determine the length to figure out the starting point of the new list, -1 or -2.

Steven Parker
Steven Parker
231,248 Points

This will work half the time, based on the length of the list. The other half of the time it will produce reverse odds instead.

Try slicing the even indexed items first, and then reversing them.