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 trialAlex Salas
3,429 Pointslast 4 from a list
I must be missing something very minor. Any clue?
# create a function named first_4
def first_4(given_list):
list(given_list) # make it a list
return given_list[:4] # return the first four items from whatever iterable is given
# create a function called first_and_last_4
def first_and_last_4(some_list) # Accepts single iterable
list_1 = some_list[:4]
list_2 = some_list[-4:]
new_list = list_1 + list_2
return new_list # returns the first 4 and last 4 items as a single value
1 Answer
Blayne Holland
19,321 PointsYour code is absolutely correct. But Looks like theres a syntax error. Add a colon after the function declaration
def first_and_last_4(some_list):
colons and semi colons get me EVERY. SINGLE. TIME. very soon you'll be so good, you'll be able to spot them from miles away. Like a sniper from seal team 6 or something. happy hunting.
Alex Salas
3,429 PointsOh my god ! - Cant believe it was that. Thank you much Blayne !
Alex Salas
3,429 PointsAlex Salas
3,429 PointsI cannot get the new_list to return the first 4 and last 4.