2 ms·
> That makes closed ranges strictly less expressive than half-open ranges, making often necessary to write special cases for zero-length. Be a little creative.
by ma2rten 13y ago
> That makes closed ranges strictly less expressive than half-open ranges, making often necessary to write special cases for zero-length.
Be a little creative. If you have slice like list[a:b] a could be the the first element and b could the length of the slice.
Alternatively the empty slice could just be b < a, instead of b <= a as it is now.
> The other big issue, as many comment, is that the arithmetic to index multi-dimensional arrays is cumbersome with 1-based indexing: for example if I is a 2d image in row-major, the element (x, y) is at position I[(y - 1) width + x] instead of I[y * width + x]*
In most cases it's better to use numpy for that anyway.
However, note that is more or less the reason we have 0-indexed arrays in C. In C the array is bascially just a another synatax for pointer arithmetics. So, I[0] is the same I + 0 * sizeof(int) (assuming I is of type of int).