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

fahad lashari
fahad lashari
7,693 Points

What am I missing from the code?

Hi I tried the code in the workspaces and in delivered the desired result from the question. However I am not sure as to exactly what the question requires?

I would appreciate any help.

Kind regards,


def first_4(string):

    return string[:4]

def first_and_last_4(string):

    new_string = string[:4] + string[-1:-4:-1]
    return new_string

2 Answers

Steven Parker
Steven Parker
229,920 Points

You may have misinterpreted the challenge.

You're really close, but the challenge wants the first 4 and last 4 items, in the original order.

Your code above will return the right items, but the last 4 will be reversed.

Try this code. It might help

def first_and_last_4(string):

new_string = string[:4] + string[-4:]
return new_string