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 trialAshmit Pathak
4,441 Pointsplz tell what to do next?
iam really stuck at this point can somebody help me with a solution...
def first_4 (iterable):
return iterable[:4]
def first_and_last_4(iterable):
return iterable[:4] + iterable[-1:-4:-1]
2 Answers
Enzie Riddle
Front End Web Development Techdegree Graduate 19,278 Points- Remember, the index on which Python stops searching is exclusive.
- You are not able to run through indexes from the end to the beginning.
Don't overthink this! You can do it! If you're still stuck, comment back. Happy coding! :)
Enzie Riddle
Front End Web Development Techdegree Graduate 19,278 PointsI apologize for taking so long to respond, hopefully you've gotten it! I said before that you are not able to run through indexes from end to beginning. In your second function, you have written
... + iterable[-1:-4:-1]
Remember that when writing slices, the order the numbers go in are Start, Stop, Step. You are starting with -1, which is the last index in your iterable, and running through your iterable backwards until you make it to index -4. You cannot run through your index this way, because it is running from end to beginning. I suggest starting with the number you want to end at.
Ashmit Pathak
4,441 PointsAshmit Pathak
4,441 Pointsiam still stuck at it....