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

Anthony Grodowski
Anthony Grodowski
4,902 Points

The code is right as far as im concerned - what should I do in order to complete the challange?

I've tested it in the REPL and it gives the same output as needed, but the treehouse program says that it's wrong (in the last part of the challange). It'd be amazing if you could help me with this weird problem!

slices.py
def first_4(word):

    items = word[0:4]
    return items

def first_and_last_4(word):
    first = word[0:4]
    last = word[-4:]
    all=first+last
    return all

def odds(item):
    var = item[1::2]
    return var

def reverse_evens(object):
    rev = object[::-1]
    thing = rev[::2]
    return thing

1 Answer

Steven Parker
Steven Parker
231,269 Points

You've got the right idea, but currently this function will only work half of the time (when the list has an odd number of items).

To get it to work in all cases, try extracting the even indexed items first, and then reversing the result.

Anthony Grodowski
Anthony Grodowski
4,902 Points

Works! Thank you, you saved me again haha(: