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 trialJaleel Rivera
1,338 PointsAs a single value
The questions asks for us to return the first and last 4 numbers of an iterable as a single value I am doing so but I continue to receive the wrong answer. What does the question mean by single value. Am I supposed to return those values in a single list or a single string ?
def first_4(val):
return val[:4]
def first_and_last_4(x):
#for loop through both lists and turn every input into a string
#try block that tests if a value or type error occurs
#once everything is string add them all together then return it
q = x[:4] + x[-1:-5:-1]
b = ''
for a in q:
b += str(a)
return b
1 Answer
Steven Parker
231,269 PointsIt sounds like you have the right idea. You nearly have a solution when you assign your variable "q".
But the instructions don't say anything about changing the item order. Take the last 4 items without reversing them.
Jaleel Rivera
1,338 PointsJaleel Rivera
1,338 PointsThanks for the help I see what you mean I was taking the last 4 by indexing the list backwards.