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

Ari Misha
Ari Misha
19,323 Points

can someone points out the issue with my code 'coz treehouse editor keeps saying "try again"

Its the 4th task of slice.py challenge where you have to return reverse of even indexed array using splice operator. Here is my code :

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

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

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


def reverse_evens(just_stop_with_slices):
        just_stop_with_slices = just_stop_with_slices.sort().reverse()  
        if len(just_stop_with_slices[]) % 2 == 0:
            return just_stop_with_slices[::2]
        else:
            return just_stop_with_slices[1::2]

1 Answer

I think author dont want you to use reverse and definitely do not sort the list as it will change the sequence.

HINT: find item with even index and then reverse the string

Solution is .

.

.

def first_4(iterable):
    return iterable[:4]


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

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


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