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 trialMoath Mha
Python Web Development Techdegree Student 1,663 PointsI'm stuck at unit 2 Challenge Task 2 of 4
"Make a new function named first_and_last_4. It'll accept a single iterable but, this time, it'll return the first four and last four items as a single value."
could you please explain what do you mean by "as a single value." ?
def first_4(iterable):
return iterable[0:4]
def last_4(iterable):
return iterable[-1:-5:-1]
def first_and_last_4(iterable):
l1 = first_4(iterable)
l2 = last_4(iterable)
return l1 + l2
nums = [1,2,3,4,5,6,7,8,9]
listo = first_and_last_4(nums)
print(listo)
1 Answer
Tyler B
5,787 PointsAs you have last_4
written now your list is returned as [1, 2, 3, 4, 9, 8, 7, 6]
changing it to
def last_4(iterable):
return iterable[-4:]
everything else in your code looks great and you should get the value as you expect.
Moath Mha
Python Web Development Techdegree Student 1,663 PointsMoath Mha
Python Web Development Techdegree Student 1,663 Pointsthanks. it worked!