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

Scott Bailey
Scott Bailey
13,190 Points

Using slices to only show odd indexes.

"Amazing! I know that one can be a little tricky!

OK, try this one on for size: create a new function named odds that returns every item with an odd index in a provided iterable. For example, it would return the items at index 1, 3, and so on."

All the steps before passed fine, and I haven't touched that code - just added new code for each step of the challenge.

I can't see what I've done wrong with the last step (the challenge question is at the top of this post)

Thanks in advance for any help!

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

def first_and_last_4(itera):
    first = itera[0:4]
    last = itera[-4:]
    return first+last

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

2 Answers

Steven Parker
Steven Parker
231,269 Points

You code looks good to me. :+1: So I pasted it directly into the challenge and it passed the first 3 tasks.

I've heard sometimes browsers can cause false failures. Try restarting your browser and then re-do the challenge.

Scott Bailey
Scott Bailey
13,190 Points

Can't believe I didn't think to try that! Just restarted the browser and it's gone through fine now! Many thanks