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 trialWilliam Forbes
21,469 PointsHelp with first_and_last_4?
Can you see my code and see if you can figure out the heck Im doing wrong?
def first_and_last_4(iterable):
iterable_stage = iterable[:4]
iterable_stage = iterable_stage + iterable[-4:]
return iterable_stage
2 Answers
Steven Parker
231,236 PointsRemember each step should add to the previous step(s).
So your original first_4 function should remain as it was for task 1, and the new function should be added to the same file (or "tab" in this case).
Otherwise, that should do just fine for task 2.
Kurt L
22,856 PointsIt looks like it should work. Just be sure not to delete the first function from part 1:
def first_4(iterable):
return iterable[:4]
You might also want to simplify your second function as:
def first_and_last_4(iterable):
return iterable[:4] + iterable[-4:]
William Forbes
21,469 PointsWilliam Forbes
21,469 PointsThank you!! And thats how I had the code originally I just changed when i couldnt get it working lol.