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 trialRonald Tse
5,798 PointsWhat's the problem with my code
I have followed the instruction:
- create a function called "first_4"
- return the first 4 item
def first_4(iterable):
return iterable[0:3]
1 Answer
Chase Marchione
155,055 PointsHi Chi,
The stop value is not included when you do a slice in Python (that, and the first value would be at 0... thus, you're returning items 0, 1, 2 and 3, which are the first four items of the iterable), so the challenge is actually looking for:
def first_4(iterable):
return iterable[0:4]
Hope this helps!