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 (Retired) Slices Slice Functions

Laknath Gunathilake
Laknath Gunathilake
1,860 Points

can't seem to pass the last step

I think I understand how I get the first and last 4 items separately, but I don't know how I get them in one list. Anyway's can't seem to pass this challenge

slices.py
def first_4(arg):
  return arg[0:4]
def odds(arg):
  return arg[1::2]
def first_and_last_4(arg):
  return (arg)[0:4]
  return (arg) [-4:]

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Laknath - You need to have one return statement. Just concatenate the two slices with + and return it. Also, you don't need parenthesis around arg.

Laknath Gunathilake
Laknath Gunathilake
1,860 Points

concatenating the two slices with a + doesnt seem to work.

def first_and_last_4(arg):
   return arg [0:4]+[-4:]
Kourosh Raeen
Kourosh Raeen
23,733 Points

You still need to use arg for the second slice:

def first_and_last_4(arg):
  return arg[0:4] + arg[-4:]