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 trialChristian A. Castro
30,501 PointsMake a function named reverse_evens that accepts a single iterable as an argument.
Any suggestions? I'm not quite what I might be doing wrong on my end? Thank you so much in advance.
def first_4(num):
return num[:4]
def first_and_last_4(num):
x = num [:4]
y =num [-4:]
return (x+y)
def odds(num):
return num [1::2]
def reverse_evens(num):
x = num[::2]
for a in x:
x.remove(a)
return x[::-1]
1 Answer
Manish Giri
16,266 PointsI'm not sure what this loop does -
for a in x:
x.remove(a)
return x[::-1]
but you've already got the evens here - x = num[::2]
. You can just reverse it by adding a [::-1]
at the end -
def reverse_evens(num):
return num[::2][::-1]