Is it possible to merge xrange and slice?

BJörn Lindqvist bjourne at
Mon Apr 30 23:00:15 CEST 2007

On 30 Apr 2007 11:02:19 -0700, Bas <wegwerp at> wrote:
> 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?

Novel idea but how would slice(3,-1) work?

mvh Björn

More information about the Python-list mailing list