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

slices

Alright, these tasks are a bit harder than the others so far in this course but I know you can do them!

In this first one, create a function named first_4 that returns the first four items from whatever iterable is given to it.

I do not know were to start. Any pointers? :/

1 Answer

Steven Parker
Steven Parker
229,744 Points

This is a basic application of a slice. Remember that the arguments to a slice are start, stop, and step, separated by colons.

Extra hint: another way to say "first four" in terms of index would be "starting at 0, stopping before 4".