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 trialNitin Kakkar
5,223 PointsNeed help In Slices.py
Need help
def first_4(var):
return var[:4]
def first_and_last_4(var):
str = var[:4] + var[-4:]
return(str)
def odds(var):
return var[1::2]
def reverse_evens(var):
x = var[1::-2]
return x
1 Answer
Steven Parker
231,236 PointsRemember that the starting index for the "evens" will be different if the list length is an even or odd number. So you'll either need to compute the start value based on the length, or you can extract the evens first and then reverse them in a separate step.
Nitin Kakkar
5,223 PointsNitin Kakkar
5,223 PointsThx