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 Slicing With A Step

fahad lashari
fahad lashari
7,693 Points

I did the last step tiny bit differently?

I did the last step like so:

numbers[-1::-1]

Both give the same answer. Are they any advantages or disadvantages or mentioning the start point? I mean, leaving it blank and then giving it the skip sequence of -1 is the same as mentioning the -1 start point. Any reason why I should or shouldn't do it?

kind regards,

Fahad

fahad lashari
fahad lashari
7,693 Points

Will Anderson

That is actually a good observation. I guess I am better of using the method which is the most common used and understood. Thanks for you input.

kind regards,

Fahad

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

I agree with Will. Promoting his comment to answer.

1 Answer

Greetings Fahad,

Technically your method [-1::-1] is correct. Both your answer and an answer like numbers[::-1] will solve the challenge for slices.py. I offer you this observation - if you were to use the [-1::-1] definition and someone else was working on this py, would they find it easy to understand, or would they go to the docs and research and retest the code, and spend extra time on a problem that is only intellectually interesting and not actually a problem?

Yours is a valid question and I enjoyed going back through the docs and (re)taking the slices.py challenge. I hope you find some value in my observation, and keep on with Kenneth's excellent lessons.