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

Miha Puc
Miha Puc
1,136 Points

How is this def reverse_evens(a): e=a[::2] e.sort(reverse=True) return e

My code achives what the task requires does it not?

slices.py
def first_4(a):
    c=a[0:4]
    return c

def first_and_last_4(a):
    c=a[0:4] 
    l=c+a[-4:]
    return l


def odds(a): 
    d=a[1::2]
    return d

def reverse_evens(a):
    e=a[::2]
    e.sort(reverse=True)
    return e

1 Answer

  1. Your answer is right if all your inputs are in sorted order.
  2. the challange is not asking to sort the list. Instead it is asking to show the elements in reverse order
  3. the challenge is about slicing the list so better use slicing options to reverse [::-1] reverses the list elements
  4. Your answer will be right if you just use reverse() method on e instead of sort(reverse=true)