I have a problem with slice().indices():
x=[0,1,2,3,4,5,6,7,8,9]*10
x[-91:-101:-3] # == [9, 6, 3, 0] OK!
x[slice(*slice(-91,-101,-3).indices(len(x)))] # == [] WRONG!
This is correct:
x[-91:-100:-3] # == [9, 6, 3] OK!
x[slice(*slice(-91,-100,-3).indices(len(x)))] # == [9, 6, 3] OK!
This is not:
x[-91:-101:-3] # == [9, 6, 3, 0] OK!
x[slice(*slice(-91,-101,-3).indices(len(x)))] # == [] WRONG!
The problem is that
slice(-91,-101,-3).indices(len(x))
returns:
(9,-1,-3)
which result in an empty list, while:
(9,None,-3)
gives the correct result. |