Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,167 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