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

Bummer: Didn't get the right values from `first_and_last_4`.

imagine, after testing this from the workspace these guys are still giving me that bummer. I JUST DON'T KNOW WHERE ITS COMING FROM.

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


def first_and_last_4(iterable):
    first_4=iterable[:4]
    last_4=iterable[-1:-5:-1]
    final=first_4+last_4
    return final

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hi Timotheus Taruvinga

You're close. I'm just not sure where you are going for the last 4? To return items from the end of a list, you just use a negative integer followed by the colon. So, to return the last 4 items you'd use -4:
If you fix up that, the rest looks good.

One more tip: You can just return the two values instead of created a third value to hold that. So, instead of creating and then returning the final value, you could just do return first_4+last_4. (It's good to remember DRY programming).

Nice work! :) :dizzy: