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

Dan Morse
Dan Morse
6,095 Points

Succeed without if statement?

Greetings! Does anyone know if there's a way to accomplish the fourth step, just using slicing? I was able to do it with len() and an if statement, but not with only slicing... Thoughts?

Thanks all!!!

2 Answers

One approach could be to get first all even index numbers and then reverse that list, this way:

 def reverse_even(iterable):
    return iterable[::2][::-1]

I hope this helps you,

Dan Morse
Dan Morse
6,095 Points

Hey Adrian, that's super helpful! Thanks! I had no idea you could stack operations that way! Nice! Thanks again! ✌🏼

You're wellcome! I've you ever need heelp, just ask. Oh, and cheers on your path to Techdegree! ;)