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

I get the result the question wants from me but it still says it didn't get the right results

My code:

def first_4(list):

return list[:4]

def first_and_last_4(list):

new_list = list[:4] + list[-4:]

return new_list

def odds(list):

return list[1::2]

def reverse_evens(list):

reversed_list = list[::-1]
new = reversed_list[::2]

return new

The reverse_evens function returns [5,3,1] like it should. However I can't pass this question because it says that the results are wrong..

slices.py
def first_4(list):

    return list[:4]


def first_and_last_4(list):

    new_list = list[:4] + list[-4:]

    return new_list


def odds(list):

    return list[1::2]


def reverse_evens(list):

    reversed_list = list[::-1]
    new = reversed_list[::2]

    return new

3 Answers

Try first getting the evens then reversing those, instead of vice versa.

def reverse_evens(list):
    evens = list[::2]
    return evens[::-1]

Then it says: Bummer: Couldn't find reverse_evens.

Is this question glitched or is my code wrong?

Ross Coe
Ross Coe
5,061 Points

@Macro - maybe an indentation error make sure you have a carriage return (cursor) over near the (left hand side numbers) gutter otherwise it may not think the function def reverse_evens is complete

Nope, the indentations are all correct. I really don't know what the problem is here.

Ross Coe
Ross Coe
5,061 Points

I mean just at the end of the def function make sure you're back over and do an extra - that worked on something else where I knew the code was right - else reach out to support if stumped - best of luck