Is it possible to merge xrange and slice?



Hi,

stupid question, but would it be possible to somehow merge xrange
(which is supposed to replace range in py3k) and slice? Both have very
similar start, stop and step arguments and both are lightweight
objects to indicate a range. But you can't do a[xrange(10,20)] and
'for i in slice(10,20)'. The only difference is see is some behavior
with infinities (e.g. object[3:] gives a slice(3,maxint) inside
_getitem_ , but I think this should not be a large problem
(xrange(0,infinity) could just yield a generator that never stops).

Which problems am I overlooking that prevent this?

Cheers,
Bas

.



Relevant Pages

  • Re: EuroPython 2006 and Py3.0
    ... be this means the notation used now has to be adapted. ... You don't think it usefull that when you need a slice as an argument ... iterate over it, it always iterates over the keys in order. ... This will allow to get rid of both range and xrange. ...
    (comp.lang.python)
  • Re: Roddick could be in trouble.
    ... but I somehow think that his problems are so ... > inherent that no coach can truly help him. ... Yes that slice is a crappy addition to his game. ...
    (rec.sport.tennis)
  • Re: Problem with Python xrange
    ... > Is this really a bug? ... No. xrange doesn't create an actual sequence you can slice, ...
    (comp.lang.python)
  • Re: Is it possible to merge xrange and slice?
    ... (which is supposed to replace range in py3k) ... and slice? ... stop and step arguments and both are lightweight ... mvh Björn ...
    (comp.lang.python)
  • Re: EuroPython 2006 and Py3.0
    ... be this means the notation used now has to be adapted. ... This will allow to get rid of both range and xrange. ... you have to introduce new syntax for an old thing. ... A slice to include the b would then be a::b. ...
    (comp.lang.python)