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

Slicing Functions

I tried this code first, at first it accepted it and took me to the next challenge. When I submitted the next challenge, it showed task 2 is not passing and when I returned to the second task to check what's wrong in with it and resubmitted it ,it showed that the function is not returning the right values (the same function which was accepted before). I don't know what's wrong in with it.

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

def first_and_last_4(lis): 
    return lis[:4:1] + lis[-1:-5:-1]

1 Answer

Steven Parker
Steven Parker
231,248 Points

For the "last 4", you'll need to set the start value appropriately, but you don't need a special end or step value. In particular, you don't want to use a negative step value because that would cause the items to be returned in reverse order.

It was really very helpful , Thanks for the help.