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

Logan Valdez
PLUS
Logan Valdez
Courses Plus Student 6,741 Points

How can I fix my code

Hello. In challenge 4 of 4 I am supposed to return all even items in reverse, however I am stumped. How can I fix my code.

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

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

def reverse_evens(reverse_list):
    return reverse_list[:1:5]

def first_and_last_4(the_other_list):
    return the_other_list[:4] + the_other_list[-4:]

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Logan,

You can't solve this with a single slice. So you'll need to do it in two steps: first, create a slice that is only evens. Next perform a reverse on it.

You already know how to create a slice of only odds, so you should be able to make a slice of only evens. I think you can figure out to create a slice that is a reverse of another slice, but if you can't, let me know and I'll give you some hints.

Cheers

Alex