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

Alexander Lausten
Alexander Lausten
3,223 Points

i dont understand number 2 challenge first_and_last_4 as a single value could you please alaborate?

am i supposed to concatenate the list to like this: somelist[:4] + somelist[-1:-5:-1] and return the output list? or add it all together to a "single value" both tells me i did'nt get the it right

please alaborate the challenge for me

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

def first_and_last_4(somelist):
    somelist = somelist[:4] + somelist[-1:-5:-1]
    number = ""
    for a in somelist:
        number += a
    return number

2 Answers

Stuart Wright
Stuart Wright
41,118 Points

Just returning the output list is fine - no need to do anything further with it. The problem is that your 'last 4' slice was incorrect. This should do the job:

def first_and_last_4(somelist):
    somelist = somelist[:4] + somelist[-4:]
    return somelist