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

wan muhammad najmie wan sabri
wan muhammad najmie wan sabri
1,943 Points

i dont understand the part return as a single value

i thought this should work but it kept saying the first task is not working now with my code

slices.py
def first_4(iterable):
    first = []
    last = []
    reverse = []
    reverse = iterable[::-1]
    first = iterable[:4]
    last = reverse[:4]
    return "".join(first) + "".join(last)

1 Answer

Steven Parker
Steven Parker
231,269 Points

It's not clear which task you are working on. The "first_4" function should simply return the first 4 items, but the code here is doing much more than that. If you've already passed that task, that function should be left as-is while you work on a different one.

And for the function that returns the first and last 4, the "last 4" part should not be reversed.

Also, you should not assume the iterable will be a list (by using "join"). It could just be a string.