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

I dont understand

Make a function named first_4 that accepts an iterable as an argument and returns the first 4 items in the iterable

slices.py
def first_4(list_1):
    return list_1(0:4:1)

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are very close. Replace the parens with square brackets:

def first_4(list_1):
    return list_1[0:4:1]

Since the default step is 1 and the default start is 0, the slice can also be written as:

return list_1[:4]

As written in your post using parens, it means call a function named list_1() with the argument [0:4:1]. This is invalid syntax for an argument and the function list_1 does not exist.

Ok, now I understand, thank you very much, you helped me a lot!!!