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 trialsaro lin
Courses Plus Student 531 PointsSilicing challenge !!
"Make a function name first_and_last_4 that accepts an iterable and returns the first 4 and last 4 items in the iterable." This is the 3rd task and I am getting error in my code..please help.. def first_4(x): return x[:4]
def odds(y): return y[1::2]
def first_and_last_4(z): returns first_4(x)+z[-4]
2 Answers
Anish Walawalkar
8,534 PointsThis should fix your problem:
def first_and_last_4(z):
return first_4(x) + z[-4:]
Sue Upton
3,723 PointsA slice of a list returns a list so they can be added together like any other list.
def first_and_last(z): return z[0:4] + z[-4:]
Jordan Bester
4,752 PointsJordan Bester
4,752 Pointsmake sure you add the z in that first_4