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

Prabhath Pillai
Prabhath Pillai
2,740 Points

What is an "iterable"?

I've been given these instructions:

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

What exactly is an "iterable"? Does this mean I should create a for loop and slice it?

slices.py
first_4 = 

1 Answer

Emil Rais
Emil Rais
26,873 Points

An iterable is a datatype that can be iterated - using a for loop. list and str are both examples of iterable datatypes.

You should create a function using the def keyword. It should be named as outlined in the challenge description. It should accept a single parameter and you should return the first four items of the iterable; slicing would indeed be an excellent way to go about that.

Prabhath Pillai
Prabhath Pillai
2,740 Points

thank you emil, you legend!