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

You're on fire! Last one and it is, of course, the hardest. Make a function named reverse_evens that accepts a single i

i can't seem to get this one

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

def first_and_last_4(treehouse):
    return treehouse[0:4] + treehouse[-4:]

def odds(lovecoding):
    return lovecoding[1::2]

def reverse_evens(lovecoding):
    even_index = lovecoding = [0, 2, 4, 6, 8]
    return reverse_even_index[-1::-1]

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Mamadou,

You're definitely on the right track. This is easiest as a two-stepper, and you've got the second step mostly right.

Step one is to get all the even indexes. Don't do any hard coding of those indexes, though - what if there was a 100-item list passed in?? Instead, use slices like you have been doing. It's exactly like odd(), but start at 0 instead of 1. Then take even_index and slice it from the very last element and work your way backwards from there. You've already got that slice written (although you're slicing a nonexistent reverse_even_index).

I bet you can get it from here. Post back and let us know!

Cheers :beers:

-Greg

Maurice Yong
Maurice Yong
9,187 Points

I'm just starting off myself, but your variable assignment doesn't look right: even_index = lovecoding = [0, 2, 4, 6, 8]

I did a quick search and uncovered this post: https://stackoverflow.com/questions/47117319/why-use-more-than-one-equal-sign-in-a-statement-with-the-same-variable

To paraphrase the poster in that thread and for the benefit of those who don't want to click away: What you've done is chain assignment which in the format you've done, is commonly used in other programming languages like C. However in Python, that format simply reads left to right and skips the middle variable, so "lovecoding" remains unmodified.

Hope that helps.