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

ODD index literable

Hi.

In the course "Python Collections" there is a question about Slices.

Create a new function named odds that returns every item with an odd index in a provided iterable. For example, it would return the items at index 1, 3, and so on. Write a function that returns new literable, with only the odd indexes.

Here is my answer

def odds(iterable):
    reverse_list = iterable[::-2]
    return new_list[::-1]

The website says that its wrong. Is there anybody that knows what is wrong with my answer?

Thanks :-)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You’re thinking in the correct direction. First, the function name should be reverse_evens. And new_list should be reverse_list.

Your code reverses the evens from the back of the list. Then it reverses this again.

Instead, get the evens in regular order, then reverse that result.

Post back if you need more help. Good luck!!!