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

Ceil-Ian Maralit
.a{fill-rule:evenodd;}techdegree seal-36
Ceil-Ian Maralit
Front End Web Development Techdegree Graduate 19,434 Points

What is wrong with this?

Hi! Can someone please tell me what is wrong with this code? The last function: It's supposed to return all the items on the list with an even index. I tried passing the list given by this challenge and I got it right.

Thank you in advance!

def first_4(items):
    return items[:4]

def first_and_last_4(items):
    first_four = items[:4]
    last_four = items[-4:]
    new_items = first_four + last_four
    return new_items

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

def reverse_evens(item):
    return item[::-2]

1 Answer

Alex Koumparos
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Ceil-Ian,

The example list in the challenge is just that, an example, of the various lists that the challenge is testing your functions with.

Behind the scenes the challenge is trying other lists, so you need to also try other lists when testing your code to make sure that it behaves the way that you think it does.

Your code does exactly what you expect for [1, 2, 3, 4, 5]. What do you expect your function to output when you try giving it [1, 2, 3, 4, 5, 6]. What do you actually get?

Hope that points you in the right direction.