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

Andrew Reidlinger
Andrew Reidlinger
1,669 Points

Not sure what I'm doing wrong here, the error states that it can't find first_and_last4

This made sense in my head, it slices the first 4 terms and for the last four terms it starts and index -1, stops at index -5 to include the last 4 terms and steps at -1 so it moves from right to left. The error says it can't find the function first_and_last4, I'm not sure why.

slices.py
iterable = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

def first_4(iterable):
    slice1 = iterable[:4]
    return(slice1)

def first_and_last4(iterable):
    slice2 = iterable[:4]
    slice3 = iterable[-1:-5:-1]
    return(slice2 + slice3)

1 Answer

Steven Parker
Steven Parker
231,269 Points

You named your function "first_and_last4", but it's looking for "first_and_last_4" (with another underscore).

You don't need to define your own "iterable" list. The challenge will call your functions with its own.

And you still need a bit of work on your "last 4" slice. Hint: like the "first 4", it can be done with only one slice parameter.