Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Slices Slice Functions

Martin Heinvee
Martin Heinvee
872 Points

Solution at workplaces gives correct output but still I get a bummer, little help please!

The problem is with the function reverse_evens. Solution at workplaces gives correct output but still I get a bummer, why ?

def first_4(item):
    return item[0:4:1]

def first_and_last_4(item2):
    return item2[0:4:1]+item2[-4::1]

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

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

2 Answers

12,964 Points

Hi Martin! You need it to take every item with an even index and return them in reverse. You need to take every item with an even index separately from trying to reverse it. So you need to add something like this to your code:

    even_index = item[::2]

This is going to take every item with an even index. I think you can figure out how to reverse this on your own. But let me know if you need any more help. :)

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

Your last method doesn't behave the way you think it does. Try it with different length lists (both odd and even numbers of elements) and you will see why.