Why does list[::-1] not equal list[:len(list):-1]?
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Fantascape Looping
--
Chapters
00:00 Why Does List[::-1] Not Equal List[:Len(List):-1]?
01:05 Answer 1 Score 2
01:27 Accepted Answer Score 6
02:00 Thank you
--
Full question
https://stackoverflow.com/questions/3690...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #slice
#avk47
ACCEPTED ANSWER
Score 6
The documentation you're referencing is the tutorial, which gives only an informal overview of Python syntax and semantics. It doesn't explain all the details. You'll note that the tutorial page you linked to doesn't even discuss negative indices.
The actual documentation is given in the library reference under sequence types.  Although it is a bit terse and not easy to understand on a first read, it does clarify  that for a slice [i:j:k]:
If i or j are omitted or None, they become “end” values (which end depends on the sign of k).
ANSWER 2
Score 2
l[::-1] is the same thing as l.__getitem__(slice(None, None, -1)).  Since the start and the stop are both None, the list will be traversed from one end to the other.  The step argument determines the direction as well as the step.