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 (2016, retired 2019) Slices Slice Functions

Yang Hu
Yang Hu
7,782 Points

about the Slice Function code challenge

so I'm on the third step of this challenge, which is to create a function named 'odds' that returns every odd index of a passed-in iterable. And It wouldn't let me pass----is my code wrong? Or is it a glitch?

slices.py
def first_4(iterable):
    return iterable[0:4]

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

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

1 Answer

Philip Schultz
Philip Schultz
11,437 Points

Hey, yes the code is currently wrong. Right now you are starting at index 0 and skipping by two(which is even indexes). Try starting at index 1 then skipping by 2, you should get odd indexes.

Yang Hu
Yang Hu
7,782 Points

Hi, Philip. So you mean the index [0] is actually considered an even index? I know 0 is an even number, but I was thinking of it as an odd index because it's the first index in the list. Anyway, thank you very much, now I got pass the challenge. :)