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

Tom Finch
Tom Finch
1,175 Points

Not sure what its asking here.

When I run this code outside of the challenge I get what I believe to be the correct result.

e.g if I had a list of numbers from 1 - 10 and ran it through the odds function It would return the numbers (2, 4, 6, 8, 10) with the Index being odd numbers. (1, 3, 5, 7, 9).

but in the challenge it get "Didn't get the right value for odds".

Any idea what I am doing wrong?

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

def first_and_last_4(items):
    first4 = items[:4]
    last4 = items[-4:]
    both = first4 + last4

def odds(items):
    oddItems = items[1::2]
Tom Finch
Tom Finch
1,175 Points

never mind, I see that I have used [] for return.

1 Answer

Steven Parker
Steven Parker
216,136 Points

Also, "return" is not a function, so you don't need parentheses around the result either:

    return both  # instead of: return(both)