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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Devin Roark](https://secure.gravatar.com/avatar/812c55a56d829f2979aa9e199fbabbc1?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Devin Roark
4,608 Pointswhen i use [::-2] on my iterable in workspaces set to the example, i get [5, 3, 1] like it asks
Not sure what I'm missing
def first_4(iterable):
return iterable[:4]
def first_and_last_4(iterable):
return iterable[:4] + iterable[-4:]
def odds(iterable):
return iterable[1::2]
def reverse_evens(iterable):
return iterable[::-2]
3 Answers
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 Pointsiterable[::-1]
produces the correct result when there are an odd count in the list, but not of there are an even number of items.
Use a two step process:
- get the even elements:
[::2]
- reverse the list:
[::-1]
These can be chained together.
Post back if you need more help. Good luck!
![Devin Roark](https://secure.gravatar.com/avatar/812c55a56d829f2979aa9e199fbabbc1?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Devin Roark
4,608 PointsEDIT: Derp i read your chain backwards. return iterable[::2][::-1]
worked for me.
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsTo be fair. My original answer had the bullets in the opposite order. I've since corrected the order.
![ds1](https://secure.gravatar.com/avatar/982c3bbbf47d9312e1e7a41d4fa6982b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
ds1
7,627 PointsI got an email about answering this, but Chris beat me haha Thanks for answering, Chris! D.
Devin Roark
4,608 PointsDevin Roark
4,608 Pointsfrom trial and error it looks like the answer is
return iterable[-1::-2]
but i'm still not sure why that works, at least why it works for a list like[1, 2, 3, 4, 5]
when the wrong answer didn't work for a list like[1, 2, 3, 4, 5, 6]