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

This works when I run it, but

It works when I run it, but it will not pass the challenge. Changing the two last lines to return iterable[::2] pass, but it should give the same result. Or is there actually some difference in the returned material that is not obvious when printed, but may be significant later?

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

def first_and_last_4(iterable):
    return iterable[:4] + iterable[-4:]
def odds(iterable):
    return iterable[1::2]
def reverse_evens(iterable):
     even_iterable = iterable[1::2]
    return even_iterable[-1::-1]

2 Answers

AJ Salmon
AJ Salmon
5,675 Points

I see two problems; one: your even_iterable variable is indented one space too many, and two: you start the even_iterable slice at 1, when it should really be started at 0, because in this challenge 0 is counted as an even number. Hope this helps!

#yours
def reverse_evens(iterable):
     even_iterable = iterable[1::2]
    return even_iterable[-1::-1]

#fixed
def reverse_evens(iterable):
    even_iterable = iterable[::2]
    return even_iterable[-1::-1]

Thank you. Good explanation. I understand.

AJ Salmon
AJ Salmon
5,675 Points

You're welcome!