Skip to content

Commit 6240240

Browse files
committed
Reverse when step is negative
1 parent b39bd4e commit 6240240

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

py/range.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,14 @@ func computeRangeSlice(r *Range, s *Slice) (Object, error) {
197197

198198
var sliceLength Int
199199
if startIndex < stopIndex {
200+
if step < 0 {
201+
startIndex, stopIndex = stopIndex-1, startIndex-1
202+
}
200203
sliceLength = (stopIndex - startIndex - 1) / stepIndex + 1
201204
} else {
205+
if step < 0 {
206+
startIndex, stopIndex = stopIndex+1, startIndex+1
207+
}
202208
sliceLength = (stopIndex - startIndex + 1) / stepIndex + 1
203209
}
204210

0 commit comments

Comments
 (0)