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
I have since solved it, I was overthinking. The challenge wanted the last four items in the same order, the piece of code below reverses them: numbers3 = numbers2[0:4] + numbers2[-1:-5:-1]
Solution: numbers3 = numbers2[0:4] + numbers2[-4::]