Grouping code by indentation - feature or ******?

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Sun Mar 27 19:10:34 CEST 2005


Jacob Lee wrote:

> About slices:
> 
> I agree that Python's slice boundaries (some_list[a:b] being all elements
> with a <= index < b) are counterintuitive at first. But this method does
> satisfy some handy properties, the first of which being:
>   l[:n] + l[n:] = l

And best of all, this is true for _every_ n, at least for the standard
slice implementations...

> Secondly, the range() function behaves identically to slices, meaning that
>   for i in range(10):
> will iterate 10 times, and
>   for i in range(len(l)):
> will iterate over the indices of the sequence l.
> 
> If you had l[a:b] be inclusive on both a and b (instead of inclusive on a
> and exclusive on b), you would have to be adding and subtracting one in
> all of these examples, leading that much more easily to off-by-one errors.

It would be not so much adding/subtracting if list indices started at 1,
but who on earth would want that? ;)

Reinhold



More information about the Python-list mailing list