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

Abdullah AlBeirouti
Abdullah AlBeirouti
2,057 Points

My code is correct, but it's telling me to try again :s

The last part of the question is telling me to return even indices in reverse. This is actually what my function "reverse_evens" is doing, but I don't know what's wrong!

slices.py
def first_4(iter):
    return iter[:4]

def first_and_last_4(iter):
    return iter[:4]+iter[-4:]

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

def reverse_evens(iter):
    if len(iter)%2 == 0:
        x=iter[-2::-2]
    esle:
        x=iter[-1::-2]
    return x

2 Answers

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Abdullah, I see a typo in the reverse_evens method. Can you spot it?

Abdullah AlBeirouti
Abdullah AlBeirouti
2,057 Points

Oh no, the else :( Thank you so much!

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey Abdullah, it is so easy to make a lot of silly mistakes. Finding them is fun and teaches you a lot. Keep up the good work.

Cheers,

Grigorij