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

I simplicitly can't figure this out.

.

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

def first_and_last_4(itt):
    return first_4(itt) + itt[-4:]

def odds(itt):
    return itt[::2]

2 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

remember that the first index is 0 which is even, and that it is also the default if you don't put a starting index. when you got the first four, you sliced with [:4] to get indices 0,1,2,3.

You need to set a starting index of 1 to capture the odds

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