Proposed PEP: New style indexing, was Re: Bug in slice type
Raymond Hettinger
python at rcn.com
Fri Aug 26 18:39:10 EDT 2005
Bryan Olson wrote:
> The conclusion is inescapable: Python's handling of negative
> subscripts is a wart. Indexing from the high end is too useful
> to give up, but it should be specified by the slicing/indexing
> operation, not by the value of the index expression.
>
>
> PPEP (Proposed Python Enhancement Proposal): New-Style Indexing
>
> Instead of:
>
> sequence[start : stop : step]
>
> new-style slicing uses the syntax:
>
> sequence[start ; stop ; step]
<klingon>
Bah!
</klingon>
The pythonic way to handle negative slicing is to use reversed(). The
principle is that the mind more easily handles this in two steps,
specifying the range a forward direction, and then reversing it.
IOW, it is easier to identify the included elements and see the
direction of:
reversed(xrange(1, 20, 2))
than it is for:
xrange(19, -1, -2)
See PEP 322 for discussion and examples:
http://www.python.org/peps/pep-0322.html
Raymond
More information about the Python-list
mailing list