inclusive-lower-bound, exclusive-upper-bound (was Re: Range Operation pre-PEP)

Alex Martelli aleaxit at yahoo.com
Sat May 12 00:09:29 CEST 2001


"Grant Edwards" <grante at visi.com> wrote in message
news:3SVK6.301$Dd5.231293 at ruti.visi.com...
> In article <3AFB0DB9.BDAE54A5 at one.net.au>, Andrew Maizels wrote:
>
> >I can see where consistency is important, but why does Python do the
> >inclusive-lower-bound, exclusive-upper-bound thing?
>
> one reason is so that for 0 <= n < len(a),
>
>     a[:n]+a[n:] == a
>
> That property makes processing sections of lists much simpler.

Yes, but, is the constraint on n necessary?  It seems to me both
by reasoning and by experiment that this nice and useful property
holds for ALL n, e.g.:

>>> a="hello world"
>>> L=len(a)
>>> for i in range(-L-1,2*L+1):
...     if a[:i]+a[i:] != a: print i
...
>>>

Many cases will be 'degenerate' by having one slice empty and
the other one covering all the sequence, but still the property
holds even then.  Or am I missing something?


Alex






More information about the Python-list mailing list