New submission from Daniel Urban <urban.dani...@gmail.com>: slice.indices behaves strangely with negative step and default stop values (note that the doc says that it "computes information about the slice that the slice object would describe if applied to a sequence of length items"):
>>> s = slice(None, None, -2) >>> s.indices(10) (9, -1, -2) >>> list(range(10))[9:-1:-2] [] >>> list(range(10))[s] [9, 7, 5, 3, 1] >>> Also with start given: >>> s = slice(8, None, -2) >>> s.indices(10) (8, -1, -2) >>> list(range(10))[8:-1:-2] [] >>> list(range(10))[s] [8, 6, 4, 2, 0] >>> Strangely giving these indices to range works: >>> s = slice(8, None, -2) >>> s.indices(10) (8, -1, -2) >>> list(range(8, -1, -2)) [8, 6, 4, 2, 0] >>> ---------- components: Interpreter Core messages: 133694 nosy: durban, mark.dickinson priority: normal severity: normal status: open title: slice.indices with negative step and default stop type: behavior versions: Python 3.1, Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11842> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com