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 trial

Python Python Collections (2016, retired 2019) Slices Slice Functions

Not sure why this is wrong. I made the function that returns first 4 and last 4 from the iterable argument from function

I tested it out in the python shell and it worked perfectly. Not sure why it isn't working here. It's not like i'm assigning a variable. I am just returning first four and last four like it said.

slices.py
def first_4(whatever):
    return whatever[0:4]

def first_and_last_4(imagine):
    return imagine[0:4] + imagine[-1:-5:-1]

1 Answer

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Hey Michael Gallego

So the challenge asks you to give you the first 4 and the last 4.

Your code is giving the first 4 and then giving the last 4, but the last 4 is in reverse order. It didn't ask for the last 4 to be in reverse.

Hope that helps! :)

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Example: If I passed in

test_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

first_and_last_4(test_data)

I should expect to get back from first_and_last_4 function.

`>>> [1, 2, 3, 4, 7, 8, 9, 10]`