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

joshua korir
joshua korir
1,445 Points

what's wrong with my code

i know join does not work on ints but how else do we join lists into single value. and what exactly does single value refer to; string or...

slices.py
def first_and_last_4(items):
    first_4 = items[0:4]
    last_4 = items[-4:]
    first_4.extend(last_4)
    first_4 ="".join(first_4)
    #value=1
    #for item in first_4:
        #value *= item
    return first_4 

2 Answers

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Joshua,

You actually had the right answer in the middle of your code - the challenge doesn't need to be all in a single string, so you can return the list you had. So if you modify your code to remove the line with the join, it should pass the challenge:

def first_and_last_4(items):
    first_4 = items[0:4]
    last_4 = items[-4:]
    first_4.extend(last_4)
    return first_4  #This is a list and that's fine!

I hope this helps!