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

Arthur Walton
seal-mask
.a{fill-rule:evenodd;}techdegree
Arthur Walton
Python Web Development Techdegree Student 3,906 Points

help with this splicing challenge

it wants me to move backwards through the list and only pull out the evens. I feel like [-1] is starting at the last spot on the list and [-2] means its moving back 2 spaces. which is the evens. is my logic incorrect? Thanks in advance.

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

def first_and_last_4(new_list):
    temp_list = new_list[:4]
    temp_list2 = new_list[-4:]
    temp_list.extend(temp_list2)
    return temp_list
def odds(new_list):
    return new_list[1::2]
def reverse_evens(new_list):
    return new_list[-1::-2]

1 Answer

Depending on if the list is Even or Odd length your solution may not work. If you start from the beginning and slice then reverse the sliced list it should work.

def reverse_evens(new_list):
    return new_list[::2][::-1]