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 slices objective won't accep functioning code

hi there , while studyin the Python->Python collections->slices at the slice functions objective i stepped into a problem , while 3/4 first objectives worked well , the 4th one that is asking for :

'Make a function named reverse_evens that accepts a single iterable as an argument. Return every item in the iterable with an even index...in reverse.'

won't accept my function , while is working as needed at the workspace . here is the function i am trying to pass :

def reverse_evens(iterable): return(iterable[::-2])

any ideas what's wring with the code ? or maybe is just a system bug .

2 Answers

Steven Parker
Steven Parker
243,656 Points

You're half right. Your method will work when the list has an odd number of items. But when the list has an even number of items, it will return reverse odds instead.

To always return reverse evens, there's two basic strategies:

  • compute the starting position based on the list size
  • extract the even index values first, then reverse them

Either one will pass the challenge when implemented correctly.

thank you steven !