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

Paulhan Carre
Paulhan Carre
1,368 Points

Task 4 / reverse_evens function help

i'd like a pointer :D

slices.py
def first_4(iterable):
    return iterable[:4]
def first_and_last_4(i):
    return i[:4] + i[-4:] 
def odds(a):
    return a[1::2]
def reverse_evens(e):
    if e[-1:] % 2 == 0:
        return e[-1::-2]

2 Answers

Stuart Wright
Stuart Wright
41,119 Points

It looks like you are testing to see if the element at index i is even. But that isn't what the challenge asks. It cares whether or not the index is even, not the element.

Personally I would complete this challenge in two stages:

  • Create a list which contains only the elements at even index.
  • Reverse the list you created in step 1.

Let me know if you need any more hints.

Paulhan Carre
Paulhan Carre
1,368 Points

hey what's an element. i know what an index is but i don't know what an element is

Stuart Wright
Stuart Wright
41,119 Points

An element just means the list item. So if you had:

['a', 'b', 'c']

You could say that the element at index 0 is 'a'.