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

Rahul Dharamdasani
Rahul Dharamdasani
1,597 Points

The reverse_evens function seems to be incorrect. Can someone point out the error ?

The reverse_evens function that I have typed out seems correct to my knowledge. I even tried to run in on pycharm and it works perfectly. But I get the error: Didn't get the desired value for reverse_evens. Am I wrong somehow ?

slices.py
def first_4(num):
    newlist = list(num)
    return newlist[0:4]

def first_and_last_4(num1):
    newlist = list(num1)
    f4 = newlist[0:4]
    l4 = newlist[-4:]
    return f4+l4

def odds(num3):
    newlist = list(num3)
    return newlist[1::2]

def reverse_evens(num):
    alist = list(num)
    return alist[-1::-2]

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Rahul,

Try your code with inputs of both even length and odd length.

This challenge can't be completed with a single slice. Think about how you could solve it by getting halfway to the solution with a single slice, then performing another slice on that result to finish it off.

Cheers

Alex