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

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

please help

my return on the "first and last 4" def is not correct, i dont now how to fix it

slices.py
def first_4(someone):
    return someone[0:4]

def odds(lottery):
    return lottery[1::2]

def first_and_last_4(yourself):
    return yourself[0:4, 5:] #and yourself[5:8]

2 Answers

The first step to this is getting the first four objects. You got that far. yourself[:4] gets the first four objects. The second step is getting the last four and this is where you are having some trouble. yourself[-4:] will give you the last four items of an iterable. Finally you need to concatenate the two parts. I've written the entire function below.

def first_and_last_4(yourself):
    return yourself[:4] + yourself[-4:]