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

Alejandro Byrne
Alejandro Byrne
2,562 Points

Challenge not working... I think

Ummm... I think i have everything right. I've completed all the steps except the last one. I checked the last one in workspaces to figure it out, and it worked. But the challenge doesn't say so.. Someone help? The last function has to return the items in index order from least to greatest evens. It should work, don't know why it says it doesn't.

slices.py
def first_4(thing):
    return thing[0:4]
def first_and_last_4(thing):
    return thing[0:4] + thing[-4:]
def odds(thing):
    return thing[1::2]
def reverse_evens(thing):
    return thing[-2::-2]

1 Answer

James J. McCombie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Points

Hello,

the problem is that you do not know the length of the list, if it is an odd number of items, your last function has problems.

I think it's better to start by slicing the list for evens as it is, therefore the length of the list has not affect...

Alejandro Byrne
Alejandro Byrne
2,562 Points

Alright, I solved it. I added an if statement seeing if it was even or odd then doing a specific slice for it. :)