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

reverse_evens runs OK on bash ---- does not pass here, why, world, why!! (>_<)

ran the function with both list as arg (as shown on ex) and passed a string in as well, both worked on bash:

[5, 3, 1]

i wonder what am i doing wrong.. thank you for looking into it!

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

def first_and_last_4(thing):
    a = thing[:4]
    b = thing[-4:]
    return a+b

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

def reverse_evens(another_thing):
    reversed_list = another_thing[::-1]
    return reversed_list[::2]

2 Answers

Stuart Wright
Stuart Wright
41,119 Points

There is a slight difference between what your function does and what the challenge asks. The challenge asks you to "Return every item in the iterable with an even index...in reverse." What you have done is reverse the iterable, then return everything that is at an even index in the reversed iterable. These two processes return the same values when your iterable has an odd number of values, but try it with [1. 2, 3, 4, 5, 6]. The challenge wants [5, 3, 1] back, but your code returns [6, 4, 2].

Hi Stuart,

thanks for helping out, i pulled the even indexed values first and then reversed the copied list, so i reversed my original code's steps =^.^= many thanks!