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 (Retired) Slices Slice Functions

Mark Casavantes
PLUS
Mark Casavantes
Courses Plus Student 13,401 Points

Why does Task 1 no longer pass? How can this be prevented? Also what am I doing wrong?

This is from Python Collections Challenge 3 of 3.

slices.py
interable = (range(1,20))

def first_4(iterable):
  return iterable[:4]

def odds(iterable):
  return iterable[1::2]

def first_and_last_4(interable):
  return interable[:4] + [-4:]
Alex Martini
Alex Martini
5,913 Points

I don't know Python, so I'm not sure if your code is correct, but I've had this issue with the challenges before. Sometimes my prior tasks no longer pass even though everything is correct. It's as if the back end gets "stuck" on the prior task, even though you are seeing the first task. Refreshing the page will correct the issue (you might want to copy your code as it will be erased)..

Hope that's it.

1 Answer

Dan Johnson
Dan Johnson
40,532 Points

You forgot to specifiy the list you're slicing for the [-4:] so just tag it on:

def first_and_last_4(iterable):
  return iterable[:4] + iterable[-4:]