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 trialPeter Alexander
4,283 PointsI'm struggling to complete the 4th Slice Function
I've tried various variations of the code without success, can someone point out the problem, thanks.
def first_4(items):
return items[:4]
def first_and_last_4(items):
return items[:4] + items[-4:]
def odds(items):
return items[1::2]
def reverse_evens(items):
evens = items[0::2]
return evens[-1::-1]
3 Answers
Peter Alexander
4,283 PointsApologies, it's with reference to:
def reverse_evens(items): evens = items[0::2] return evens[-1::-1]
Brandon Crossley
10,287 Pointsforgot my rules for a second. looks like this is correct. I got a pass for this challenge using your code
Mustafa Başaran
28,046 PointsHi Peter,
The fist index in the slice is the starting point. So, you can omit the first -1 in the return statement in the last function.
return evens[::-1]
The above statement will return the reversed version of the evens list. You can also take 0 out in
evens = items[0::2]
The above slice is equal to
evens = items[::2]
I hope this helps.