Apr-27-2020, 09:23 PM
According to the documents:
s[i:j:k]
5.The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that 0 <= n < (j-i)/k. In other words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping when j is reached
The last sentence says that if k (step) is negative, we start at the end and work back toward j (stop).
To do what you want you need to do two slices.
numbers[:5][::-2]
s[i:j:k]
5.The slice of s from i to j with step k is defined as the sequence of items with index x = i + n*k such that 0 <= n < (j-i)/k. In other words, the indices are i, i+k, i+2*k, i+3*k and so on, stopping when j is reached
The last sentence says that if k (step) is negative, we start at the end and work back toward j (stop).
To do what you want you need to do two slices.
numbers[:5][::-2]