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

First 4 and last 4 values of an iterable, what output am I looking for?

I may be missing what output the question is looking for. I also tried ' '.join(a) to put first 4 and last four as one value. Thanks!

slices.py
def first_4(item):
    item_list = list(item)
    copy_item_list = item_list[:]

    return copy_item_list[:4]

def first_and_last_4(item):
    item_list = list(item)
    copy_item_list = item_list[:]

    first_4 = copy_item_list[:4]
    last_4 = copy_item_lsit[-4:]

    a = first_4.extend(last_4)

    return a
Cheo R
Cheo R
37,150 Points

I got first_and_last_4 to pass by returning a list made of the first 4 and last 4.

Did not use join to return them as a string.

Okay cool that is the way I'm doing it above. Do you see anything in my code I'm missing?

Thank you... always the little things. I also discovered in going through the forums that I was over complicating this. Thanks for the help!

Cheo R
Cheo R
37,150 Points

One thing that has helped with code challenges is to try to make test to run with my code. Sometimes it'd take some time to figure out what they're testing for but I think in the end it's worth it.

1 Answer

You have a typo in spelling list here

last_4 = copy_item_lsit[-4:]