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

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