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 trialAnureet kaur
3,570 PointsSlicing Functions
I tried this code first, at first it accepted it and took me to the next challenge. When I submitted the next challenge, it showed task 2 is not passing and when I returned to the second task to check what's wrong in with it and resubmitted it ,it showed that the function is not returning the right values (the same function which was accepted before). I don't know what's wrong in with it.
def first_4(x) :
return x[0:4]
def first_and_last_4(lis):
return lis[:4:1] + lis[-1:-5:-1]
1 Answer
Steven Parker
231,248 PointsFor the "last 4", you'll need to set the start value appropriately, but you don't need a special end or step value. In particular, you don't want to use a negative step value because that would cause the items to be returned in reverse order.
Anureet kaur
3,570 PointsAnureet kaur
3,570 PointsIt was really very helpful , Thanks for the help.