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 trial

Python Python Collections (2016, retired 2019) Slices Slice Functions

plz tell what to do next?

iam really stuck at this point can somebody help me with a solution...

slices.py
def first_4 (iterable):
    return iterable[:4]
def first_and_last_4(iterable):
    return iterable[:4] + iterable[-1:-4:-1]

2 Answers

Enzie Riddle
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Enzie Riddle
Front End Web Development Techdegree Graduate 19,278 Points
  1. Remember, the index on which Python stops searching is exclusive.
  2. 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! :)

iam still stuck at it....

Enzie Riddle
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Enzie Riddle
Front End Web Development Techdegree Graduate 19,278 Points

I 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.