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 trialIdris Abdulwahab
Courses Plus Student 2,961 PointsSlices
Quiz challenge: Please help! 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. For example, with [1, 2, 3, 4, 5] as the input, the function would return [5, 3, 1].
I tried to solve it in two ways:
First attempt:
def reverse_evens(pull):
return pull[-1::-2]
Second attempt:
def reverse_evens(pull):
bravo = [:]
give = []
for num in bravo:
if num%2 = 0:
give.append(num)
return give[-1::-1]
def first_4(one):
return one[:4]
def first_and_last_4(two):
return two[:4] + two[-4:]
def odds(numbers):
return numbers[1::2]
def reverse_evens(pull):
bravo = pull[:]
give = []
for num in bravo:
if num%2 = 0:
give.append(num)
return give[-1::-1]