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

Mimon Copitman
Mimon Copitman
1,242 Points

i don't understand it, im getting an error "Couldn't find `first_and_last_4'"

i think i wrote it right but it giving error "Couldn't find `first_and_last_4'"

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

def first_and_last_4(list):
    return li[:4] + li[-4:len(li):1]

5 Answers

your code is this:

def first_4(list):
    return list[0:4]

def first_and_last_4(list):
    return list[:4] + list[-4:len(li):1]

when you use len(li) you have to use len(list) not li. And that "1"? at the end is a step, you don't hawe to use it

return list[:4] + list[-4:]
Mimon Copitman
Mimon Copitman
1,242 Points

no, something isn't right still it giving that error, here's my code:

def first_4(list): return list[0:4]

def first_and_last_4(list): return list[:4] + list[-4:len(li):1]

Mimon Copitman
Mimon Copitman
1,242 Points

ok guys it worked , silly me!