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

Brian Wilkes
Brian Wilkes
4,731 Points

first_and_last_4 issue

"OK, this second one should be pretty similar to the first. Make a new function named first_and_last_4. It'll accept a single iterable but, this time, it'll return the first four and last four items as a single value."

i think i am doing what is being asked, at least my own workspace works. Can anyone see any reason they say its not correct?

thanks!

slices.py
def first_4(list1):
  first_4 = list1[0:4]
  print(first_4)

def first_and_last_4(list1):
  first = list1[0:4]
  last = len(list1)-4
  last_4 = list1[last:]
  first_and_last_4 = first + last_4
  print(first_and_last_4)

1 Answer

Brian Wilkes
Brian Wilkes
4,731 Points

Never mind I forgot to return the answer...