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

Could someone advise if it is possible to slice around items in a list? I'm having trouble wrapping my head this concept

I have exhausted my brain of ways to try this. I'm not looking for answers to this Challenge, just some support in understanding the slice concept a little better. I've tried to extend additional variables, and while it would produce the correct answer as far as the numbers are concerned it would only work for the specific instance I created, not for any iterable provided as an argument.

slices.py
def first_4 (first_list = list(range(10))):
    return first_list[:4]

def first_and_last_4(first_list = list(range(10))):
    return first_4([4:])

2 Answers

Steven Parker
Steven Parker
231,236 Points

You don't need to provide any default arguments for the functions in this challenge. The challenge will always pass in arguments for testing.

For task 2, if you want to call your task 1 function you'll need to pass along the argument to it. You won't need a slice for the first part because the other function does that for you. But you will need to combine that with a separate slice to add on the "last 4" part.

Thanks Steven, this definitely helped me figure out the logic of this scenario. Still working on the solution, but I appreciate your assistance :D