Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.

def first_4(iterable):
    return iterable[:4]

def first_and_last_4(iterable):
    return final

1 Answer

Jason Anders
Jason Anders
Treehouse Moderator 145,704 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: