[Python-ideas] [Python-Dev] PEP Proposal: Revised slice objects & lists use slice objects as indexes
g.brandl at gmx.net
Mon Mar 10 18:44:05 CET 2008
Neil Toronto schrieb:
> Alexandre Vassalotti wrote:
>> On Sun, Mar 9, 2008 at 7:21 PM, Forrest Voight <voights at gmail.com> wrote:
>>> This would simplify the handling of list slices.
>>> Slice objects that are produced in a list index area would be different,
>>> and optionally the syntax for slices in list indexes would be expanded
>>> to work everywhere. Instead of being containers for the start, end,
>>> and step numbers, they would be generators, similar to xranges.
>> I am not sure what you are trying to propose here. The slice object
>> isn't special, it's just a regular built-in type.
>> >>> slice(1,4)
>> slice(1, 4, None)
>> >>> [1,2,3,4,5,6][slice(1,4)]
>> [2, 3, 4]
>> I don't see how introducing new syntax would simplify indexing.
> Likewise. It would simplify looping, though:
> >>> for i in 1:5:
> ... print i
See http://www.python.org/dev/peps/pep-0204/ for a similar proposal.
More information about the Python-ideas