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


Michael Dioszeghy
Michael Dioszeghy
2,412 Points

Issue in Python code challenge with Slices

I am working on task 4 in a code challenge and in the workspace, my output looks correct, but the task keeps saying the answers are wrong and I'm not sure why. https://teamtreehouse.com/library/python-collections-2/slices/slice-functions

The task is:

Make a function named reverse_evens that accepts a single iterable as an argument. Return every item in the iterable with an even index...in reverse.

For example, with [1, 2, 3, 4, 5] as the input, the function would return [5, 3, 1].

and my function is:

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

Any help is appreciated!

Your code is hard to interpret the way you have it. Please put your code in code blocks by surrounding them with 3 back tics ```. Click on the Markdown Cheatsheet for help.

Michael Dioszeghy
Michael Dioszeghy
2,412 Points

updated to put the code in code blocks

1 Answer

Michael Dioszeghy
Michael Dioszeghy
2,412 Points

I have figured this out.. My code worked in repl, but was not doing what the challenge required.