Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,862 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