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 trialMimon Copitman
1,242 Pointsi 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'"
def first_4(list):
return list[0:4]
def first_and_last_4(list):
return li[:4] + li[-4:len(li):1]
5 Answers
reanimator313
6,005 Pointsyour 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:]
Thananjaya Chakravarthy
4,672 Pointsit must be
return [list[:4]+list[-1:-5:-1]]
james south
Front End Web Development Techdegree Graduate 33,271 Pointswhat is li? it is undefined and causing the error.
Mimon Copitman
1,242 Pointsno, 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
1,242 Pointsok guys it worked , silly me!