I could not find something similar.
Given, e.g.
lst = Range[10]
(* {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} *)
the following gives the reverse of lst
(I know about Reverse
).
lst[[-1 ;; 1 ;; -1]]
(* {10, 9, 8, 7, 6, 5, 4, 3, 2, 1} *)
Why the following does not return the same output?
lst[[;; ;; -1]]
Thanks.
Span
, right? Otherwise it starts by default from the beginning. Is there any similar concept to Mathematica with Python's slicing? (Thanks for the commenf by the way!) $\endgroup$Span
andPart
compared to Python's slicing? So far you have only shown that Mathematica uses a slightly different syntax. $\endgroup$lst[::-1]
gives thelst
reversed without prividing any start/end value. $\endgroup$1
and end position toAll
it cannot use;; ;; -1
to produce the list reversed. See;; ;; -1 // InputForm
. $\endgroup$