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 trialManfredi Martorana
19,470 PointsSlicing
Hi, I don't understand how to complete Python Slicing Challenge. In particular I don't know how to slice the first 4 and the last 4 elements of a list.
Thanks for the help ;)
3 Answers
Manfredi Martorana
19,470 PointsWell, I don't know how to write a function that accept a list, and return the first and last four elements.
Thank you
Manfredi
eugeneteo
112 PointsI have not worked on that challenge, but I think this is what you are asking:
>>> def sublist(lst):
... return # add your slicing code here
...
>>> sublist(str)
('hell', 'orld')
>>> sublist(a)
([1, 2, 3, 4], [7, 8, 9, 10])
Eugene
Manfredi Martorana
19,470 PointsPerfect... One last thing: the output must be in the same bracket!
Manfredi
eugeneteo
112 PointsTry to work on the answer. You are almost there with these hints. Good luck!
Manfredi Martorana
19,470 PointsThank you!!!
Bye Bye
eugeneteo
112 Pointseugeneteo
112 PointsHi Manfredi,
Take a look at the following two examples. I hope this will help you understand slicing better.
Eugene