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

Nikhil Alexander
Nikhil Alexander
1,444 Points

im trying to reverse the even index's of the argument given...i tried this code... its not passing

i really thought about this code and i hoped it would work.... please help me out

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

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

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

def reverse_evens(word):
    if len(word) % 2 == 0:
        return word[-2::-2]
    else:
        return word[-1::-2]    

1 Answer

Steven Parker
Steven Parker
231,248 Points

Your solution looks correct to me. So I pasted it directly into the challenge and it passed!

It doesn't pass for you?

Nikhil Alexander
Nikhil Alexander
1,444 Points

Yeah the code passed today...i dont know why it wasnt passing the other day..anyway thanks for looking into this Steven