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

Heidi Bada
Heidi Bada
14,197 Points

I wanted odds in the return. Did I use the wrong syntax or misunderstand the question?

I get odd numbers in the resulting list, but it's not what the question is looking for. I can't see the question at the moment, but it was asking for a function that returns an odd index in the iterable.

slices.py
def first_4(item):
  my_list=list(range(1,5))
  for item in my_list:
    return my_list[:4]

def odds(odd_item):
  odd_list=list(range(0,20))
  for odd_item in odd_list:
    return odd_list[1::2]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Your odds() function is working too hard. You only have to operate on the iterable passed in:

def odds(odd_item):
    #odd_list=list(range(0,20))
    #for odd_item in odd_list:
    return odd_item[1::2] #<-- changed to operate on the input parameter