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

Dimitar Tsvetkov
Dimitar Tsvetkov
6,806 Points

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

Please explain why is my code not working

slices.py
first_4 = [0, 1, 2, 3, 4]
frist_4[:4]

2 Answers

So as far as I can tell you need to use def to create a function. If you wanted a function to return every third item it would look like this def everyThird(iter): return iter[::3]

Dimitar Tsvetkov
Dimitar Tsvetkov
6,806 Points

Thank you Alvin. I can't believe I am so stupid. No sleep leads to lack of reading comprehension :D