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.


Martin Heinvee
Martin Heinvee
872 Points

Task about using slices-solution not passing the challenge.

In python collections course I am stuck with the following task:

Challenge Task 2 of 4: Make a new function named first_and_last_4. It'll accept a single iterable but, this time, it'll return the first four and last four items as a single value.

My solution gets a 'bummer' for the following solution: If item2 = 'kukeleegu' then my solution gives 'kukeugee' and if item2 = [1,2,3,4,5,6,7,8,9] then 12349876. I believe that these are correct answers and solution should be bassed but I will get a 'bummer', why ? Can anyone help me with that ?

def first_and_last_4(item2):
    for i in item2:
    string1 = ''.join(uus) 
    return string1[0:4:1]+string1[-1:-5:-1]

2 Answers

Steven Parker
Steven Parker
216,121 Points

It looks like you're reversing the order of the last 4 items, but the instructions don't ask for that. Just return the first and last 4 items in their original order.

Martin Heinvee
Martin Heinvee
872 Points

Thanks for the comment Steven! Yes the last four were backwards, but still the solution is not passed. I re-posted the issue in a better form.