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

Rakesh Bharadwaj
Rakesh Bharadwaj
1,376 Points

I got proper output but this shows it is not correct

def reverse_evens(list4): a = list4[::-2] return a

print(reverse_evens([1,2,3,4,5]))

Gives [5,3,1]

slices.py
def first_4(list1):
    a = list1[:4]
    return a

def first_and_last_4(list2):
    a = list2[0:4]
    b = list2[-4:]
    return a+b

def odds(list3):
    print(list3)
    a = list3[1::2]
    return a

def reverse_evens(list4):
    a = list4[::-2]
    return a

1 Answer

Stuart Wright
Stuart Wright
41,119 Points

Your function works if your list has an odd number of elements, as in your example.

Try instead passing it the list [1, 2, 3, 4, 5, 6]. Your function will return [6, 4, 2], but the challenge wants you to return [5, 3, 1].

You need two steps to complete this challenge correctly - first identify those elements at an even index, then reverse them.