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

reverse_evens

Hi i am currently stuck on the reverse_evens code challenge, I used the following code and also saw the other posts on the forum.

def reverse_evens(iterable):
    return iterable[::-2]

Here comes my real question though, the assignment says the following:

Make a function named reverse_evens that accepts a single iterable as an argument. Return every item in the iterable with an even index...in reverse.

Doesn't this mean that the function is supposed to return the values at a even index and not specifically the even numbers? English is not my native language so forgive me if i am not understanding this properly

2 Answers

Steven Parker
Steven Parker
243,656 Points

Your English may be better than you think, your understanding is correct.

The task is to return the values that have even-numbered indexes. You will not need to test any of the values themselves.

Bonus hint: There's two basic strategies to solve this. One is to compute the start position based on the even/odd-ness of the list. The other is to extract the even indexed values first, and then reverse them with a separate slice. Either method works when implemented correctly (but the second one may be easier). :wink:

Allright, then why doesn't my function work since it does exactly that?

I am kinda confused

Steven Parker
Steven Parker
243,656 Points

Are you sure it does it in all cases? The size of the list might affect the outcome. See the bonus hint I added to my answer.

Yeah i commented too quick, i realize what is going wrong now! Thanks for helping!