Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

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
221,292 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.