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 trialMatthew O'Brien
2,622 PointsIs this just a cheap way out? Why doesn't this work?
My code works. I just added something I found on stackoverflow (reverse=True). I'm sorting which may not be what was intended, but the result is the same. What am I missing?
def first_4(iter):
return iter[:4]
def first_and_last_4(iterab):
total = iterab[:4] + iterab[-4:]
return total
def odds(iter):
return iter[1::2]
def reverse_evens(iter):
total = iter[::2]
total.sort(reverse=True)
return total
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsSorting isn't necessary to reverse a list. There is also reversed() and slices
# built in command
total = reversed(total)
# slicing
total = total[::-1]