Arithmetic sequences in Python

Tom Anderson twic at urchin.earth.li
Mon Jan 16 20:21:21 EST 2006


On Mon, 16 Jan 2006, Alex Martelli wrote:

> Steven D'Aprano <steve at REMOVETHIScyber.com.au> wrote:
>
>> On Mon, 16 Jan 2006 12:51:58 +0100, Xavier Morel wrote:
>>
>>> For those who'd need the (0..n-1) behavior, Ruby features something 
>>> that I find quite elegant (if not perfectly obvious at first), 
>>> (first..last) provides a range from first to last with both boundaries 
>>> included, but (first...last) (notice the 3 periods)
>>
>> No, no I didn't.
>>
>> Sheesh, that just *screams* "Off By One Errors!!!". Python deliberately 
>> uses a simple, consistent system of indexing from the start to one past 
>> the end specifically to help prevent signpost errors, and now some 
>> folks want to undermine that.
>>
>> *shakes head in amazement*
>
> Agreed.  *IF* we truly needed an occasional "up to X *INCLUDED*" 
> sequence, it should be in a syntax that can't FAIL to be noticed, such 
> as range(X, endincluded=True).

How about first,,last? Harder to do by mistake, but pretty horrible in its 
own way.

tom

-- 
Socialism - straight in the mainline!



More information about the Python-list mailing list