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 trialbehar
10,799 PointsWhat is wrong with the final step. It works perfectly fine in the shell
What wrong with this this code?
def first_4(itr):
return itr[0:4]
def first_and_last_4(itr):
return itr[0:4] + itr[-4:]
def odds(itr):
return itr[1::2]
def reverse_evens(itr):
del itr[1::2]
return itr[::-1]
2 Answers
Steven Parker
231,248 PointsI tried this for myself to see that it does appear to work. But I'm baffled as to why — since a slice returns a copy of a list, I don't understand how a "del" operation performed on it can possibly affect the original list.
But as a suggestion for passing the challenge: instead of deleting the items you don't want, try extracting the ones you do want and then reversing them.
behar
10,799 PointsLol realised imidiately after posting that i can just do:
whatever = itr[0::2]
So i got it, ty!
behar
10,799 Pointsbehar
10,799 PointsI dont know how to do this, i tried using the pop feature but you cant say:
new_list = itr.pop([0::2])