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

Bruno Paris
Bruno Paris
3,568 Points

what am i doing wrong

i don´t see the mistake here, what could it be?

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

def first_and_last_4 (whatever):
    s= whatever[:4]
    a = whatever[-4:]
    return s+a

def odds (whatever):
    c = list(whatever)
    return c[1::2]

def reverse_evens (whatever):
    c = list(whatever)
    return c[::-2]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are close! Currently, the code is returning every other item from the back of the list. This may or may not be the even-indexed items because it depends on the length of the collection.

>>> reverse_evens([0, 1, 2, 3, 4, 5])
[5, 3, 1]
>>> reverse_evens([0, 1, 2, 3, 4, 5, 6])
[6, 4, 2, 0]

It's better to use a two-step approach. Get the even-indexed items, then reverse it.

Post back if you need more help. Good luck!

Bruno Paris
Bruno Paris
3,568 Points

done! thank you chris