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

returns the first four characters from an iterable. It does that in eclipse running python 3. what is the problem?

It works in eclipse. produces an iterable. My only guess is that it needs to work with strings too.

slices.py
def first_4(first):
  return list(range(first,first+4))

first_4(1)

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

1 is an integer, not an iterable. The function takes an iterable, like a list, and returns the first four items from that iterable.

ok I misunderstood. I understand now. I thought it would take something that can be sequential and only take the first 4 from it. instead it wants an long list and only displays the first four of that list. Ok. Thanks!