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!

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


Im stuck on the slices challenge :(


I am stuck on task 2, where it asks for the first and last 4 items in a given iterable, returned as a single value. I have attached my code, as it keeps saying the function does not return the right answer. Any suggestions would be much appreciated :(


def first_4(numbers): return numbers[0:4]

def first_and_last_4(numbers2): numbers3 = numbers2[0:4] + numbers2[-1:-5:-1] numbers3 = ''.join(str(element) for element in numbers3) return numbers3

1 Answer

Robert Ionut Muraru
.a{fill-rule:evenodd;}techdegree seal-36
Robert Ionut Muraru
Full Stack JavaScript Techdegree Graduate 22,194 Points


The way I solved this one was:

  1. stored the first 4 elements in a variable
  2. stored the last 4 elements in another variable
  3. returned the concatenation (+) of these 2 variables. Don't know if this is the best way to do it but it works.