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

Tom Finch
Tom Finch
1,248 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?

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

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

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

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

1 Answer

Steven Parker
Steven Parker
231,269 Points

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

    return both  # instead of: return(both)