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

The challenge is unclear . . . !

My code for this Challenge is:

def odds(lst): lst = [1, 2, 3, 4, 5, 6, 7, 8, 9] return lst[1::2]

I got this back:

Bummer! odds() didn't return the right output. Got [2, 4, 6, 8], expected kaoa

The numbers 2, 4, 6, 8 are at indexes '1, 3, 5, 7' which are odd indexes. I don't understand the problem here. Would someone clarify all this for me?

slices.py
def first_4(lst):
  lst = [1, 2, 3, 4, 5, 6, 7]
  return lst[:4]

def odds(lst):
  lst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  return lst[1::2]

2 Answers

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Cheri.

The problem here is that you hard coded the iterable, which is something we do not want here.

Just get rid of the lists you have manually created and the compiler will take care of it (the code challenge as a built-in iterable to check your code against). In other words, for these first 2 tasks of the challenges, inside the function you will only have the return statement.

Vittorio

Thank you very much.