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 trialOlyadi Angassa
4,051 Pointsi really don't know what's wrong with my code tried it on IDLE on my computer it worked but does't work in the challenge
challenge says output should be single value of the first and last four elements of any iterable
def first_4(x):
return x[:4]
def first_and_last_4(y):
return (y[:4]+y[-5:]
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsYou are very close! Check your last index. There also appears to be a closing paren missing.
>>> [1,2,3,4,5,6,7,8,9,10][-5:]
[6, 7, 8, 9, 10]
>>> [1,2,3,4,5,6,7,8,9,10][-4:]
[7, 8, 9, 10]
Post back if you need more help. Good luck!!!
Olyadi Angassa
4,051 PointsOlyadi Angassa
4,051 PointsThank you, I tried it and it worked.