Re: [Python-ideas] [Python-Dev] PEP Proposal: Revised slice objects & lists use slice objects as indexes

Alexandre Vassalotti wrote:
Likewise. It would simplify looping, though: >>> for i in 1:5: ... print i 1 2 3 4 >>> Since this kind of loop happens frequently, it makes sense to shorten it. Slice objects (and syntax) seem ready-made for that - it wouldn't be *new* syntax, just repurposed syntax. Though Forrest didn't bring this up directly, I've often thought that Python's having both xrange and slice (and in 3000, range and slice) is mostly vestigial. Their information content is identical and their purposes are highly analogous. Unifying them would reduce the number of new concepts for a beginner by one, and these are frequently-used concepts at that. Negative indexes could throw the idea for a loop, though. (Pun! Ha ha!) And this makes the colons look like some kind of enclosure: >>> for i in :5: ... Neil


participants (2)
-
Georg Brandl
-
Neil Toronto