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 trialigor corrales
2,474 PointsI think I don't understand challenge 4 of 4
My problem is this sentence :
Return every item in the iterable with an even index...in reverse.
For example, with [1, 2, 3, 4, 5] as the input, the function would return [5, 3, 1].
Because I did what the sentence ask for in my code but the program give me this:
"Don't get the right results"
def first_4(rango1):
f = rango1[0:4]
return f
def first_and_last_4(rango):
b = rango[0:4]
c = rango[-4:]
d = b + c
return d
def odds(iterable):
return iterable[1::2]
def reverse_evens(rango4):
a = rango4[-1::-2]
return a
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, igor corrales! I think you do understand what the challenge wants just fine and your code does work but only in half the cases. Your code works when the number of items in the iterable is an odd number. If I sent in [1, 2, 3, 4, 5, 6] to your code, I would expect to still get back [5, 3, 1] because those are the items in the iterable at even indexes and then in reverse. Instead, what I get back is [6, 4, 2]
. They give you an example, but the example they give is clearly not what they're sending in. You will need to account for what happens when the length of the iterable is an even number as well.
Use this line for testing:
print(reverse_evens([1, 2, 3, 4, 5, 6]))
Hope this helps!